Skip to content

pantoken / renderers/rehype/src / rehypePantokenIcons

函数: rehypePantokenIcons()

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

实验性

一个 rehype 插件工厂。返回一个转换器,将 :code: 令牌重写为内联 SVG。

参数

options?

RehypeOptions = {}

RehypeOptions.

返回值

一个 unified/rehype 转换器。

(tree) => void

示例

内置图标集

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");

编写 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.