Updated View as Markdown

Diagram rendering

Diagram rendering

Renders fenced ```mermaid / ```d2 blocks in Markdown, and standalone *.mmd / *.d2 files referenced from Markdown, to SVG (default) or PNG ([diagrams] format = "png" / --diagram-format png). Mermaid rendering is mermaid-rs-renderer (pure Rust, no browser or Node); D2 rendering is d2-little (pure Rust port of the d2lang pipeline). PNG conversion is resvg/usvg with one embedded font (fonts/DejaVuSans.ttf, Bitstream Vera license, permissive) so output is byte-identical across CI runners regardless of which fonts a runner’s host happens to have installed. A render error is fatal and names the Markdown file and the line the fenced block opened on, or the file referenced; an unrecognized fence language is left as a code block untouched.

DiagramKind::from_fence_info

pub fn from_fence_info(info : & str) -> Option < Self >;

The kind a fenced code block’s info string names, by its first word (case-insensitive); None for any other language, which is left as a code block untouched.

DiagramKind::from_extension

pub fn from_extension(extension : & str) -> Option < Self >;

The kind a standalone file’s extension names, by *.mmd / *.d2.

RenderedDiagram

pub struct RenderedDiagram { pub resolved_path : String, pub bytes : Vec < u8 >, pub file : String, pub line : usize, }

One diagram rendered to bytes, keyed by the repo-relative path its Markdown reference resolves to (a real file for a standalone *.mmd / *.d2 reference, a synthetic same-directory name for a fenced block) so it flows through the same upload/rewrite map as an ordinary media file.

render

pub fn render(kind : DiagramKind, source : & str, format : DiagramFormat, file : & str, line : usize,) -> Result <(Vec < u8 >, & 'static str), DiagramError >;

Renders source (the fence body or a standalone file’s content) to SVG or PNG bytes, returning the extension the chosen format uses.

render_fenced_diagrams

pub fn render_fenced_diagrams(file : & str, content : & str, format : DiagramFormat,) -> Result <(String, Vec < RenderedDiagram >), DiagramError >;

Replaces every fenced ```mermaid / ```d2 block in content (the Markdown source of file, a repo-relative path) with an image reference to a synthetic same-directory file, and renders each to bytes per format. A fence with any other info string is left untouched. Returns the rewritten content and the rendered bytes, keyed by the synthetic reference’s resolved path so they flow through the same media upload and link rewrite as an ordinary local file.

render_standalone_references

pub fn render_standalone_references(root : & std::path::Path, refs : & [MediaReference], format : DiagramFormat,) -> Result <(Vec < MediaReference >, Vec < RenderedDiagram >), DiagramError >;

Partitions refs (the media references the link rewrite found) into standalone *.mmd/*.d2 files and everything else, rendering the former to bytes keyed by their own resolved repo path (unchanged, since that is the exact destination the Markdown source already points at) so they flow through the same upload/rewrite map as any other media reference. A read or render failure is fatal and names the Markdown file and line the reference was found at.

Back to top