Skip to main content

Crate md2any

Crate md2any 

Source
Expand description

md2any — Markdown -> PowerPoint / OpenDocument / PDF / Word / Writer / HTML / SVG / PNG.

§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 | html ::write
 or svg::write_files for one SVG/PNG per slide
       ↓
 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 options = md2any::paginate::PaginationOptions {
    break_mode: md2any::paginate::BreakMode::Smart,
    fill: 0.9,
    table_fit: md2any::paginate::TableFit::Auto,
    ..Default::default()
};
let slides = md2any::paginate::paginate_for_layout_with_options(
    slides, &theme, &layout, options,
);
let bytes = md2any::pdf::write(
    &slides, &theme, &layout, "talk", "Author",
    std::path::Path::new("."), None, None, None, 0.4, None, false,
    md2any::pdf::NotesPageSize::Slide, md2any::pdf::NotesLayout::Auto, None,
)?;
std::fs::write("talk.pdf", bytes)?;

Modules§

diagram
External diagram renderers (Graphviz dot, Mermaid mmdc, PlantUML).
document
Shared controls for flowing document outputs.
docx
Microsoft Word DOCX export.
font
Embedded TrueType fonts used for PDF output.
front_matter
YAML front-matter extractor.
html
Native HTML deck renderer.
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 preprocessor. Not a real TeX engine — 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 runtime renderer.
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.
render_plan
JSON diagnostics for the post-parse/post-pagination deck.
serve
Minimal preview server for --serve. No deps beyond std.
svg
SVG and PNG slide-image export.
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.