Get-md now preserves Mermaid diagrams through document-to-Markdown conversion

mrspence1 pts0 comments

get-md v1.7.0 is out. Where 1.6.0 taught the library to read PDF, DOCX, and Markdown, this release is about not throwing away the one thing a Markdown converter usually destroys: Mermaid diagrams . v1.7.0 preserves Mermaid fences it finds, recovers the source from diagrams a browser has already rendered to , optionally reconstructs diagrams drawn into a PDF using a vision model, and optionally checks that whatever comes out actually parses. It also fixes a handful of real bugs surfaced along the way, including a validation path that was almost always wrong.

Built by the Nano Collective, a community collective building AI tooling not for profit, but for the community.

What changed

Four diagram behaviours, on by default where they can be, opt-in where they need optional dependencies:

Preserved. A ```mermaid fence in your HTML or Markdown comes out the other side unchanged, fence and language tag intact. Same treatment for dot, graphviz, and plantuml, all newly registered as recognised language identifiers.

Recovered. When a docs site has already rendered a diagram to (the GitHub, MkDocs, and Docusaurus case), get-md pulls the original source back out of the DOM before Readability and the HTML cleaner can strip it.

Reconstructed. Diagrams drawn into a PDF can be rebuilt by a remote vision model. Opt-in, capped at the first 10 pages, and remote providers only.

Validated. validateMermaid: true parses every Mermaid block in the finished Markdown and annotates the ones that fail, keeping the original so you can repair it rather than losing it.

These cover the same problem from four angles, and each one is independently switchable. The default install footprint is unchanged. New capabilities that need rendering or parsing install their own optional peer dependencies.

Preserved: Mermaid fences survive conversion

mermaid is now a recognised language identifier, alongside dot, graphviz, and plantuml. Previously a Mermaid block survived only by accident, through a loose lowercase-word fallback with no test coverage behind it.

A ```mermaid block in HTML () or in a Markdown file comes out the other side unchanged, fence and language tag intact. The behaviour applies from both the library and the CLI, across HTML, URL, and .md input.

The release also fixes a general case that affects every syntax-highlighted page, not just Mermaid: the Mermaid recovery work sets keepClasses: true, so keeps its class through extraction. Fenced output is now tagged, ```python, ```go, ```rust, where it previously came out bare. This is the most visible change in the release for anyone converting documentation sites. Two consequences worth knowing: unrecognised class names can now surface as tags via the lowercase-word fallback, and because element classes survive into the cleanup pass, class-based noise rules match more often (a cookie-notice block is correctly dropped, but so is genuine prose carrying an advertisement or popup class).

Recovered: Mermaid source from rendered SVG

GitHub, MkDocs, and Docusaurus run mermaid.js client-side, so the HTML you fetch holds the rendered , not the diagram. The source is usually still in the DOM somewhere, and get-md now goes looking for it before Readability and the HTML cleaner can strip it.

The recovery looks for these container shapes:

.mermaid, pre.mermaid, [data-processed="true"], svg[id^="mermaid-"], and svg.mermaid.

For each container it tries the first source it can find, in this order:

A inside or next to the container.

A data-code, data-mermaid, data-src, data-original, or data-source attribute.

The container's own text when it is a holding no .

A hidden pre[hidden], , or textarea[hidden].

The SVG's , , or aria-label.

That last fallback is deliberately strict. mermaid.js writes accessibility strings such as Created with Mermaid into those nodes, and emitting one as a diagram would be worse than dropping it. Text qualifies only if it is multi-line, contains ;, or opens with a diagram keyword and carries an arrow, a colon, or real length.

Recovered diagrams are re-emitted as ```mermaid fences. Where no source is recoverable, behaviour is unchanged: the SVG's text labels fall through as loose text.

Reconstructed: diagrams in PDFs by a vision model (opt-in)

A diagram in a PDF is vector drawing or raster image. There is no text to recover, so this is a vision problem. With useLLM and a remote vision-capable model, get-md renders PDF pages to images and asks the model to emit Mermaid inline where the diagram appeared.

A few constraints worth stating up front:

Remote providers only. The local ReaderLM-v2 path is text-only, and so is useLLM with no llm config, since that defaults to local-llama. Neither renders pages nor calls a vision model.

New optional peer dependencies. pdfjs-dist (^5) and @napi-rs/canvas (^0.1), installed only if you want this. Standard fonts resolve dynamically from the installed pdfjs-dist.

Capped at the first 10 pages , to keep long PDFs from...

mermaid diagrams source diagram markdown from

Related Articles