@lnkkerst/rehype-pre-language
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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>

Dependents (0)

Package Sidebar

Install

npm i @lnkkerst/rehype-pre-language

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

6.05 kB

Total Files

7

Last publish

Collaborators

  • lnkkerst