Skip to main content

Optional plugins

Math, syntax highlighting, diagrams, and CJK-friendly emphasis are optional. Install only what your interface renders. A missing plugin has a readable fallback instead of making the renderer fail.

PluginAddsGuide
Codehighlight.js syntax colors for settled blocks and streamed linesCode highlighting
MathKaTeX rendering for inline and display TeXKaTeX math
DiagramLazy-loaded Mermaid fencesMermaid diagrams
CJKEmphasis rules that work around CJK punctuationCJK emphasis

Install​

npm install katex remark-math rehype-katex
npm install rehype-highlight
npm install mermaid
npm install remark-cjk-friendly

Configure once​

import { katexPlugin } from "@aeven-ai/hypermarkdown/plugins/math";
import { highlightPlugin } from "@aeven-ai/hypermarkdown/plugins/code";
import { mermaidPlugin } from "@aeven-ai/hypermarkdown/plugins/mermaid";
import { cjkPlugin } from "@aeven-ai/hypermarkdown/plugins/cjk";
import "katex/dist/katex.min.css";
import "highlight.js/styles/github-dark.css";

const plugins = {
math: katexPlugin(),
code: highlightPlugin(),
diagram: mermaidPlugin({ theme: "neutral" }),
cjk: cjkPlugin(),
};

<HyperMarkdown md={markdown} plugins={plugins} />

Build plugin objects once or memoize them. A new object can require new processing pipelines.

Graceful fallbacks​

Missing pluginResult
Math$x$ remains literal text
CodeCode remains cached with controls and line numbers, but unhighlighted
DiagramMermaid fences render as ordinary code
CJKStandard CommonMark emphasis rules apply

Mermaid loading​

Mermaid is dynamically imported on first use. A document without diagrams never downloads it. The opening Mermaid fence starts loading while the rest of the diagram is still arriving; set preload when diagrams are expected immediately.

Keep plugin identities stable​

Create plugins at module scope or memoize them. HyperMarkdown reuses frozen processing pipelines, and a new plugin object can require new pipelines. The Mermaid plugin also retains its loaded engine inside the plugin object.

Custom feature plugins​

The exported MathPlugin, CodeHighlighterPlugin, DiagramPlugin, and CjkPlugin interfaces let you replace the default engines without exposing arbitrary processor mutation through the component API.