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]):

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:

  1. Preprocess the input Markdown via md2star.preprocess_markdown().

  2. 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 from deraison.ai cached under XDG, and finally the bundled template. --no-remote-templates / --offline skip the fetch.

  3. Invoke pandoc with the bundled Lua filter, metadata defaults, and resolved reference doc.

  4. Postprocess (DOCX only) — re-inject the MyTable / MyTableSmall table styles that Pandoc strips when rewriting word/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.

Author

[Warith HARCHAOUI](https://linkedin.com/in/warith-harchaoui/)

md2star.cli.main(argv=None)[source]

Console entry point: md2star <subcommand>.

Subcommands:

  • docx / pptx / pdf — convert (same flags as the standalone aliases md2docx / 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.

Parameters:

argv (list[str] | None)

Return type:

int

md2star.cli.md2docx_main(argv=None)[source]

Console entry point: md2docx.

Parameters:

argv (list[str] | None)

Return type:

int

md2star.cli.md2pdf_main(argv=None)[source]

Console entry point: md2pdf.

Parameters:

argv (list[str] | None)

Return type:

int

md2star.cli.md2pptx_main(argv=None)[source]

Console entry point: md2pptx.

Parameters:

argv (list[str] | None)

Return type:

int