@lnkkerst/rehype-pre-language
v0.1.0
Published
Rehype plugin to inject language type into the pre element.
Downloads
4
Maintainers
Readme
rehype-pre-language
Rehype plugin to inject language type into the pre element.
Installation
npm install @lnkkerst/rehype-pre-language
# or use yarn
yarn add @lnkkerst/rehype-pre-language
# or use pnpm
pnpm install @lnkkerst/rehype-pre-language
Usage
import rehypePreLanguage from "@lnkkerst/rehype-pre-language";
import { readFileSync } from "node:fs";
import rehypeParse from "rehype-parse";
import rehypeStringify from "rehype-stringify";
import { unified } from "unified";
const doc = readFileSync("./example.html");
const file = await unified()
.use(rehypeParse)
.use(rehypePreLanguage)
.use(rehypeStringify)
.process(doc);
console.log(String(file));
Input
<html>
<head></head>
<body>
<pre>
<code class="language-javascript">console.log("hello world")</code>
</pre>
</body>
</html>
Output
<html>
<head></head>
<body>
<pre data-language="javascript">
<code class="language-javascript">console.log("hello world")</code>
</pre>
</body>
</html>