Convert Markdown with Mermaid diagrams and SVG illustrations to professional Word documents
tier
standard
applyTo
**/*docx*,**/*word*,**/*md-to-word*,**/*export*
muscle
.github/muscles/md-to-word.cjs
inheritance
inheritable
Markdown to Word Conversion
One command to professional Word documents — diagrams, tables, and formatting done right on first attempt.
Convert any Markdown document into polished Word (.docx) files ready for stakeholders, executives, and external audiences. Supports all standard Markdown formatting, Mermaid diagrams (auto-converted to PNG), and SVG illustrations (auto-embedded).
# Academic paper with TOC
node md-to-word.cjs thesis.md --style academic --toc
# Professional report with cover
node md-to-word.cjs quarterly-report.md --style professional --cover --toc
SVG Image Handling
SVG files are automatically detected and converted to PNG for Word compatibility:
<!-- This SVG reference in your Markdown... -->

<!-- ...becomes this embedded PNG in Word -->
{width=5.8in}
node md-to-word.cjs doc.md --debug --keep-temp
# Check _debug_combined.md for preprocessed content# Check images/ folder for generated PNGs
macOS Fallback (No Pandoc)
macOS ships textutil which can convert HTML to DOCX natively:
# Convert markdown to HTML first, then HTML to DOCX
npx marked document.md -o document.html
textutil -convert docx document.html -output document.docx
Feature
Pandoc (primary)
textutil (fallback)
Table styling
Full (via jszip post-processing)
Basic
Mermaid diagrams
Supported (pre-rendered PNG)
Must be pre-rendered
Heading styles
Mapped to Word styles
Basic HTML mapping
Cross-references
Supported
Not supported
Install
brew install pandoc
Built-in (macOS only)
Limitations: textutil needs HTML input (not raw Markdown), produces simpler formatting, and doesn't support the table styling or image sizing that md-to-word.cjs provides. Use only when Pandoc is unavailable and a quick conversion is needed.
Batch Processing
Convert a Folder
# Windows PowerShell
Get-ChildItem docs/*.md | ForEach-Object {
node .github/muscles/md-to-word.cjs $_.FullName --style professional
}
# macOS/Linuxfor f in docs/*.md; do
node .github/muscles/md-to-word.cjs "$f" --style professional
done
Recursive Directory
# All .md files in docs/ and subdirectories
node .github/muscles/md-to-word.cjs docs --recursive --style professional
Watch Mode
# Auto-rebuild when source changes
node .github/muscles/md-to-word.cjs spec.md --watch
Integration Examples
GitHub Actions CI/CD
# Generate Word docs as build artifacts-name:GenerateWordDocumentsrun:|
npm install -g @mermaid-js/mermaid-cli svgexport
node .github/muscles/md-to-word.cjs docs/spec.md --toc --cover
-name:Uploadartifactsuses:actions/upload-artifact@v4with:name:word-documentspath:docs/*.docx
npm Script
{"scripts":{"docs:word":"node .github/muscles/md-to-word.cjs docs/README.md --style professional --toc"}}
For Heir Projects
Copy .github/muscles/md-to-word.cjs to your project
Copy shared modules from .github/muscles/shared/ (markdown-preprocessor, mermaid-pipeline)