pyssg is pre-1.0 and under active development - APIs, config, and themes may change.
pyssg.plugins.mermaid

1 min read

pyssg.plugins.mermaid

Mermaid client-side diagram plugin.

Client-side rendering is the default: a fenced mermaid code block is rewritten into markup the mermaid.js browser library understands, namely <pre class="mermaid">...</pre>. The layout is responsible for loading mermaid.js lazily; this plugin performs only a pure HTML transform and never fetches or renders SVG (that is the opt-in build-time path, not implemented here).

Ordering: the markdown plugin renders at parse stage 200 and the syntax-highlight plugin runs at stage 250. This plugin taps stage 230 so it consumes mermaid blocks before highlighting would touch them, leaving every other code block intact.

The transform is pure: it depends only on its input HTML string, never on a clock or randomness, so two builds of the same input are byte-identical. This plugin only rewrites derived node.meta HTML; it owns no graph algorithm or cache state (plugins declare facts, the engine owns invalidation).

Stdlib only; no third-party dependency is needed for client-side rendering.

clientside_mermaid(html_text: str) -> str

Rewrite mermaid code blocks for client-side rendering by mermaid.js.

Every <pre><code class="language-mermaid">ESCAPED</code></pre> becomes <pre class="mermaid">UNESCAPED</pre>. The diagram text is HTML-unescaped (e.g. A--&gt;B back to A-->B) because the mermaid.js library reads the raw text content of the <pre class="mermaid"> element. All other code blocks and surrounding HTML are left unchanged.

class MermaidPlugin

Rewrites mermaid code blocks into client-side mermaid.js markup.

MermaidPlugin.apply(self, builder: Builder) -> None

mermaid() -> MermaidPlugin

Factory used in pyssg.config.py.