Skip to main content

Crate md2any

Crate md2any 

Source
Expand description

md2any — Markdown → PowerPoint / OpenDocument / PDF / Word / Writer.

§Pipeline overview

 markdown source
       ↓
 front_matter::extract       (split YAML header from body)
       ↓
 parser::parse               (pulldown-cmark → IR slides)
       ↓
 diagram::pre_render         (shell out for dot/mermaid/plantuml)
       ↓
 paginate::paginate          (split overlong slides into "(cont.)")
       ↓
 toc::inject (optional)      (auto Contents slide)
       ↓
 one of: pptx | odp | pdf | docx | odt ::write
       ↓
 bytes

Every step operates on plain in-memory data — there’s no disk I/O after the initial markdown read until the final byte buffer is written out. That keeps the whole conversion in the millisecond range and makes --watch / --serve trivial to implement.

§Crate layout

§Library use

The CLI binary in main.rs is the canonical consumer, but the same modules are reachable from integration tests and external code. A minimal embed looks like:

let md = std::fs::read_to_string("talk.md")?;
let (front, body) = md2any::front_matter::extract(&md);
let theme = md2any::theme::Theme::resolve("light", "16:9", None)?;
let layout = md2any::layout::Layout::resolve("clean")?;
let slides = md2any::parser::parse(&body, &front, "talk");
let slides = md2any::paginate::paginate(slides, &theme);
let bytes = md2any::pdf::write(
    &slides, &theme, &layout, "talk", "Author",
    std::path::Path::new("."), None, None, None, 0.4, None, false, None,
)?;
std::fs::write("talk.pdf", bytes)?;

Modules§

diagram
External diagram renderers (Graphviz dot, Mermaid mmdc, PlantUML).
docx
Microsoft Word DOCX export.
font
Embedded TrueType fonts used for PDF output.
front_matter
YAML front-matter extractor.
image
Image loading: local files, remote URLs, SVG rasterisation, plus a visible placeholder when anything fails.
ir
Intermediate representation for the deck.
layout
Layout selection — the visual frame a slide is dressed in.
lint
Optional --check mode. Walks the post-paginated slide tree and reports issues that won’t cause a build failure but would hurt the final deck: over-long titles, narrow tables in portrait, code lines that won’t wrap cleanly, etc. Writes warnings to stderr and returns the count.
math
Tiny LaTeX-flavoured math to Unicode translator. Not a real math renderer — just enough to make $E = mc^2$ and \sum_{i=1}^n f(x_i) look reasonable in a slide deck without pulling in a TeX engine.
odp
OpenDocument Presentation (.odp) writer.
odt
OpenDocument Text (ODT) export.
paginate
Slide pagination — splits a parsed deck into rendered slides.
parser
Markdown → slide IR parser.
pdf
PDF writer — pure Rust, no external PDF library.
pptx
PowerPoint OOXML (.pptx) writer.
serve
Minimal preview server for --serve. No deps beyond std.
syntax
Tiny per-language tokenizer for code-block syntax highlighting.
theme
Theme definitions — colour palettes, fonts, slide dimensions.
toc
Auto Table-of-Contents slide.

Functions§

slides_snapshot
Render the parsed/paginated slide tree as a stable, human-readable text snapshot. Used by golden-file tests to assert that parser changes don’t silently alter the deck structure.