Rendering and themes
Integrate with your app
Section titled “Integrate with your app”Create one reader after its element mounts. In React, Vue, or another UI framework, call the integration from the component’s client-side lifecycle, then call dispose() on unmount.
const options: RendererOptions = { appearance: "auto", outlineMode: "sidebar" };
function mountDocument(container: HTMLElement, source: string) { const reader = render(container, source, options);
return { replace(nextSource: string) { return reader.update(nextSource, options); }, dispose() { reader.destroy(); }, };}Pass a new Markdown snapshot to update(source, options) when the source or reading settings change. Supply the desired options on each call. Resource resolver callbacks belong to the initial mount. If your document’s base URL or permission context changes, the callbacks must use the current access context. If the old callbacks close over the previous document, destroy the reader and mount it with new callbacks.
Use the built-in sidebar or Wave outline, or set outlineMode: "off" when your app supplies its own. The custom outline API can attach an outline to an element you provide.
Set appearance and typography
Section titled “Set appearance and typography”appearance: "auto" follows the mount’s appearance when specified, otherwise the system. Your app can request light or dark explicitly. Set theme.background and theme.foreground for the reading surface, and use reading to adjust the font, size, line height, and width. See reading options and results for accepted ranges.
const darkOptions: RendererOptions = { appearance: "dark", theme: { background: "#161b22", foreground: "#e6edf3" }, reading: { fontSizePx: 16, lineHeightPx: 27, contentWidthPx: 720 },};
reader.update(source, darkOptions);Style Mermaid and PlantUML
Section titled “Style Mermaid and PlantUML”Mermaid and supported PlantUML diagrams use the active reader colors. Their labels follow the reading size. The reader keeps nodes, relationship lines, and guides visually distinct. Mermaid pie charts separate categories; Gantt charts distinguish task states. Supported PlantUML diagrams use these defaults when the source has no explicit local style.
Set the following CSS custom properties on the reader’s mount before rendering. Changes made by the host can be applied with update().
#sfm-document { --sfm-diagram-accent: #3274d9; --sfm-diagram-corner-radius: 6; --sfm-diagram-stroke-width: 1.5;}| Property | Value |
|---|---|
--sfm-diagram-accent |
Six-digit hex accent. The reader link color is used when it resolves to a hex or RGB value, with a blue fallback. |
--sfm-diagram-corner-radius |
Unitless CSS pixels, 0–24. Default 4. |
--sfm-diagram-stroke-width |
Unitless CSS pixels, 0.5–4. Default 1.25. |
--sfm-diagram-fill-strength |
Percent of accent mixed into the background, 0–100. Default 13. |
--sfm-diagram-line-strength |
Percent of foreground mixed into the background, 0–100. Default 64. |
See the live Mermaid and PlantUML examples in the product handbook.