pele README

项目的 README,来自 github.com/obsidianmd/pele。合并为一个 markdown 文件:README.md。

Pele

Pele renders Mermaid diagrams to SVG. It is small, synchronous, has no runtime dependencies, and uses CSS variables for colors and fonts.

Pele supports every diagram type built into Mermaid 12.1.0.

Documentation, examples, and a playground are at pele.run.

Install

npm install pele

Or load it from a CDN:

<script src="https://cdn.jsdelivr.net/npm/pele@1/dist/pele.global.js"></script>
<script>
  for (const el of document.querySelectorAll('pre.mermaid')) pele.mount(el, el.textContent);
</script>

Use

import { render } from 'pele';

const { svg } = render(`flowchart LR
  A[Mermaid text] --> B[SVG]`);

document.querySelector('#diagram').innerHTML = svg;

In a browser, mount() renders into an element, reads fonts from CSS, and adapts the layout to the container width:

import { mount } from 'pele';

mount(document.querySelector('#diagram'), text);

See the API for options and error handling.

The main entry point includes every diagram type. Reduce the initial bundle size by registering individual types or loading them on demand:

import { register, render } from 'pele/core';
import flowchart from 'pele/diagrams/flowchart';

register(flowchart);
import { renderAsync } from 'pele/lazy';

const { svg } = await renderAsync(text);

Theme

Set CSS variables on the diagram or a parent element to customize colors and fonts:

.pele {
  --pele-bg: #fffcf0;
  --pele-fg: #100f0f;
  --pele-muted: #6f6e69;
  --pele-line: #100f0f;
  --pele-surface: #f2f0e5;
  --pele-surface-alt: #e6e4d9;
  --pele-border: #cecdc3;
  --pele-accent: #205ea6;
  --pele-font: sans-serif;
  --pele-radius: 4px;
}

Charts use --pele-series-1 through --pele-series-8. Colors adapt to theme changes without being re-rendered. See Theming for all variables, fonts, and class names.

Security

Pele escapes diagram text, filters links and styles, and limits source and output size. See Security for handling untrusted diagrams, displaying errors, and supplying icons.

Compatibility

Pele targets Mermaid 12.1.0 syntax, with its own layout and visual style. Its parsers are tested against Mermaid's parser specs and with differential fuzzing.

Develop

npm install
npm test
npm run build
npm run bench

npm run bench:mermaid times Pele and Mermaid.js in headless Chrome on the same diagrams and compares bundle sizes. It needs Node 22 or later. It fetches Mermaid 12.1.0 from unpkg; pass -- --mermaid <version> for another release, and set CHROME if Chrome is not in /Applications.

The documentation site and playground are in website/ and use Node 24 and pnpm 12. With nvm:

cd website
nvm use
pnpm install
pnpm dev

After installing the website dependencies, run npm run test:website from the repository root to check the playground.

See Contributing for parser testing.

License

MIT. The specs under tests/compat and the grammar files beside them come from Mermaid, which is also MIT licensed.

pele (obsidianmd/pele)

正在搜索数据库…

4.6K ·GitHub
这是什么?Pele 是一个轻量级库,可将 Mermaid 图表渲染为 SVG,主打速度快,且没有运行时依赖。
这是完整的图表库,还是只是一个 Mermaid 渲染器?它是专门的 Mermaid 渲染器,而不是通用图表库:它将 Mermaid 图表语法转换为 SVG,并支持 Mermaid 12.1.0 内置的全部图表类型。
我怎么把它加到项目里?可以将它作为包安装,或直接从 CDN 加载,然后在浏览器中调用 mount(),把图表渲染到一个元素里。
使用它需要先安装 Mermaid.js 吗?不需要。Pele 自带解析器,且没有运行时依赖,因此它不依赖 Mermaid.js 库本身,只依赖兼容的 Mermaid 语法。
它支持 Mermaid 的所有图表类型吗?支持。主入口涵盖 Mermaid 12.1.0 的所有图表类型,不过你也可以单独注册某些类型,或按需加载,以减小打包体积。
用不可信的用户输入来渲染图表安全吗?Pele 会转义图表文本、过滤链接和样式,并限制源码和输出的大小,这些措施正是为了让渲染不可信的图表更安全。
我怎么自定义图表的颜色和字体?在图表元素或其父容器上设置 CSS 变量即可;图表系列使用 --pele-series-1 到 --pele-series-8,颜色会实时更新,无需重新渲染。
我为什么要选 Pele,而不是 Mermaid 自带的渲染器?Pele 是一个小巧、同步、无依赖的 SVG 渲染器,专注于速度;其解析器经过 Mermaid 自身解析器规范的测试,并通过差分模糊测试来保证兼容性。
如果只需要几种图表类型,我能缩小打包体积吗?可以。你无需导入完整入口,只注册实际用到的图表类型,或按需加载其他类型即可。
大小
2.9 MB
星标
4.6K
时长
1个月
提交 · 90 天