md2star.cli module
md2star command-line interface.
This module replaces the legacy heredoc’d shell wrappers (scripts/install.sh
used to write ~/.local/bin/md2docx and ~/.local/bin/md2pptx directly).
Now there is exactly one source of truth — this file — and four console
entry points (registered in pyproject.toml [project.scripts]):
md2docx <input.md> [options...]→md2docx_main()md2pptx <input.md> [options...]→md2pptx_main()md2pdf <input.md> [options...]→md2pdf_main()md2star <subcommand> [options...]→main()
The subcommand form (md2star docx / md2star pptx / md2star pdf)
is the canonical spelling; the md2docx / md2pptx / md2pdf aliases
exist so users do not have to relearn anything.
The CLI is intentionally thin: it parses md2star-specific flags, forwards everything else verbatim to pandoc, and orchestrates the four-step pipeline:
Preprocess the input Markdown via
md2star.preprocess_markdown().Resolve the reference template: prefer
template.{docx,pptx}next to the input file, then the legacy.pandoc-reference.{docx,pptx}, then the XDG cache, then (the default since v2.5.0) a one-shot fetch fromderaison.aicached under XDG, and finally the bundled template.--no-remote-templates/--offlineskip the fetch.Invoke pandoc with the bundled Lua filter, metadata defaults, and resolved reference doc.
Postprocess (DOCX only) — re-inject the
MyTable/MyTableSmalltable styles that Pandoc strips when rewritingword/styles.xml.
The PDF format is implemented as a wrapper: it produces the DOCX first
(so all the md2star polish — mermaid, table styles, slide-aware tweaks —
applies) and then asks headless LibreOffice (soffice --headless
--convert-to pdf) to render that DOCX to PDF. This guarantees the PDF
visually matches the DOCX you would ship.
- md2star.cli.main(argv=None)[source]
Console entry point:
md2star <subcommand>.Subcommands:
docx/pptx/pdf— convert (same flags as the standalone aliasesmd2docx/md2pptx/md2pdf).gui— launch the local Overleaf-style Markdown → PDF editor.doctor— print an environment diagnostic.cache-dir— print the resolved cache directory path.clear-cache— wipe the cache directory.