Convert a Markdown file to a .docx document with a native Word table of
contents, embedded filesystem images, and style-based heading auto-numbering.
For development (creates a local .venv):
uv syncTo install md2word globally as a command on your PATH (requires
Task):
task install # uv tool install .Use task install-dev for an editable install (local source changes take
effect immediately) and task uninstall to remove it.
Installed globally:
md2word INPUT.md [-o OUTPUT.docx] [--strip-numbering] [--toc-levels N] [--reference-doc PATH]Or without installing, from the project directory:
uv run md2word INPUT.md [-o OUTPUT.docx] [--strip-numbering] [--toc-levels N] [--reference-doc PATH]- Output defaults to
INPUT.docx. --strip-numberingremoves existing1.,1.2,Chapter N:prefixes from headings so they are not numbered twice.--toc-levelssets both the TOC depth and the numbering depth (default 3).--reference-docsupplies a pandoc reference docx for base styling (fonts, colors); numbering and TOC auto-update are always applied on top.
- Python removes any existing Markdown "Table of Contents" block (a native Word TOC is always generated instead) and optionally strips heading numbers.
- Pandoc converts the Markdown to
.docx, embedding images and inserting a native TOC field. The reader is pandoc markdown withlists_without_preceding_blanklineandtask_listsenabled, so LLM/CommonMark-style lists that immediately follow a text line (no blank line) render as real lists instead of one run-on paragraph. - Python post-processes the
.docxto attach a multilevel decimal numbering definition to the Heading styles and to setupdateFields, so Word renders1,1.1,1.1.1and refreshes the TOC when the document is opened.
Numbering comes entirely from Word styles — no numbers are typed into the text.
task test # or: uv run pytest