Skip to content

pantoken / renderers/rehype/src / rehypePantokenIcons

Hàm: rehypePantokenIcons()

rehypePantokenIcons(options?): (tree) => void

Thử nghiệm

Một factory plugin rehype. Trả về một bộ biến đổi (transformer) thay thế các token :code: thành SVG nhúng.

Tham số

options?

RehypeOptions = {}

RehypeOptions.

Trả về

Một bộ biến đổi unified/rehype.

(tree) => void

Các ví dụ

Bộ biểu tượng tích hợp sẵn

ts
import { unified } from "unified";
import rehypeParse from "rehype-parse";
import rehypeRaw from "rehype-raw";
import rehypeStringify from "rehype-stringify";
import { rehypePantokenIcons } from "@pantoken/rehype";

const html = await unified()
  .use(rehypeParse, { fragment: true })
  .use(rehypePantokenIcons)
  .use(rehypeRaw) // required: the icon body is a raw SVG node
  .use(rehypeStringify)
  .process("go :arrow-left: back");

Soạn bộ phân giải cho plugin brand-icon

ts
import { rehypePantokenIcons } from "@pantoken/rehype";
import { simpleIcons } from "@pantoken/plugin-simple-icons";
import * as registry from "simple-icons";

unified().use(rehypePantokenIcons, { plugins: [simpleIcons({ registry })] });
// :github: now resolves from simple-icons; unknown codes stay literal text.