@limn-hl/rehype 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +38 -0
  2. package/dist/index.js +13 -3
  3. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @limn-hl/rehype
2
+
3
+ Rehype plugin for [`limn-hl`](https://github.com/ekesti/limn). Builds HAST `<span>` nodes directly from `eachToken` with zero HTML re-parsing.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install limn-hl @limn-hl/rehype
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import rehypeLimn from "@limn-hl/rehype";
15
+ import { detectIn } from "limn-hl/detect";
16
+ import { all } from "limn-hl/lang";
17
+ import { tokyoNight } from "limn-hl/theme";
18
+ import rehypeStringify from "rehype-stringify";
19
+ import remarkParse from "remark-parse";
20
+ import remarkRehype from "remark-rehype";
21
+ import { unified } from "unified";
22
+
23
+ const html = String(
24
+ unified()
25
+ .use(remarkParse)
26
+ .use(remarkRehype)
27
+ .use(rehypeLimn, {
28
+ registry: all(),
29
+ theme: tokyoNight,
30
+ lineNumbers: true,
31
+ detect: detectIn,
32
+ })
33
+ .use(rehypeStringify)
34
+ .processSync(markdown),
35
+ );
36
+ ```
37
+
38
+ Pass a custom `new Registry([...])` instead of `all()` and omit `detect` to tree-shake unused languages and the detector. See [`docs/integrations.md`](https://github.com/ekesti/limn/blob/main/docs/integrations.md) for full options and CSS-class styling.
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  kindName,
5
5
  TokenKind
6
6
  } from "limn-hl";
7
+ import { FontStyle } from "limn-hl/theme";
7
8
  export function rehypeLimn(options) {
8
9
  const { registry, theme, detect } = options;
9
10
  const prefix = options.classPrefix || "limn";
@@ -17,9 +18,18 @@ export function rehypeLimn(options) {
17
18
  continue;
18
19
  }
19
20
  const col = theme?.tokens[k] ?? "";
20
- if (col || kind === TokenKind.Comment) {
21
- const style = col && kind === TokenKind.Comment ? `color:${col};font-style:italic` : col ? `color:${col}` : "font-style:italic";
22
- spanProps[k] = { style };
21
+ const styleBits = theme?.styles?.[k] ?? 0;
22
+ if (col || styleBits) {
23
+ const parts = [];
24
+ if (col)
25
+ parts.push(`color:${col}`);
26
+ if (styleBits & FontStyle.Bold)
27
+ parts.push("font-weight:bold");
28
+ if (styleBits & FontStyle.Italic)
29
+ parts.push("font-style:italic");
30
+ if (styleBits & FontStyle.Underline)
31
+ parts.push("text-decoration:underline");
32
+ spanProps[k] = { style: parts.join(";") };
23
33
  }
24
34
  }
25
35
  let blockStyle = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limn-hl/rehype",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Rehype plugin for synchronous syntax highlighting with limn (zero HTML re-parsing)",
5
5
  "keywords": ["limn", "limn-hl", "rehype", "rehype-limn", "syntax-highlighting", "unified", "mdx"],
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "dist"
27
27
  ],
28
28
  "peerDependencies": {
29
- "limn-hl": "^0.5.0"
29
+ "limn-hl": "^0.7.0"
30
30
  },
31
31
  "scripts": {
32
32
  "build:js": "bun build src/index.ts --root src --outdir dist --format esm --no-bundle --target browser",