Loading...
Loading...
Markdown to Word Document Skill. Convert Markdown documents to professionally formatted Word documents that comply with Chinese typesetting standards, supporting multiple preset formats. Suitable for converting formal documents, papers, reports, and other documents requiring standardized typesetting.
npx skill4agent add cat-xierluo/legal-skills md2wordpip install python-docx Pillow beautifulsoup4 PyYAMLnpm install -g @mermaid-js/mermaid-cli # Mermaid diagram rendering
brew install librsvg # SVG→PNG (recommended, rsvg-convert)
# or pip install cairosvg # SVG→PNG alternative
# or npm install puppeteer # SVG→PNG alternative (scripts/svg2png.js)Inlineblocks in the content will be automatically rendered as PNG and embedded. The rendering priority is rsvg-convert → cairosvg → svg2png.js(puppeteer); any one of the three is sufficient. If none are available, it will fall back to displaying the SVG source code in a code block.<svg>...</svg>
scripts/md2word.py# Basic conversion
python scripts/md2word.py input.md output.docx
# Use preset format
python scripts/md2word.py input.md --preset=academic
# Use custom configuration
python scripts/md2word.py input.md --config=my-config.yaml
# Footnote/endnote mode (default footnote is page footnote; endnote=end-of-document notes + superscript numbering)
python scripts/md2word.py input.md --notes=endnote
# Book merging: multiple chapter md files → single docx (table of contents + chapter division by input files + header, specify output with -o)
python scripts/md2word.py --book ch01.md ch02.md ch03.md -o book.docx --preset=book-publishonly converts the boundaries between adjacent input files into new sections. Markdown horizontal lines--book,---,***in chapter content will be retained as horizontal lines in both single-chapter and book modes, and do not bear pagination or chapter division semantics.___
will resolve local relative image paths according to the directory where each chapter's Markdown is located before merging, then write to a temporary merged draft. Both Markdown images and HTML--bookare supported; HTTP/HTTPS, data URI, anchors and absolute paths remain unchanged. The image resolution process for single-chapter conversion remains the same.<img src>
Thepreset by default starts a new page for Markdown titles whose text is exactly "Chapter Summary" or "Hands-on Practice"; the converter writes Word nativebook-publishin the title paragraph itself, without inserting empty paragraphs, pagination runs or new sections. This rule also applies to single-chapter conversion, and is disabled by default in other presets; it can be overridden viapageBreakBefore.pagination.page_break_before_headings
When the sameappears repeatedly in the content, the native[^label]mode will generate independent Word footnotes for each occurrence and repeat the same definition text, ensuring that the footnote can be seen at each reference position; thefootnotemode still reuses the same number and one endnote definition.endnote
In nativemode, when two footnote markers are directly adjacent in the source code, the output will add a 9pt superscript NBSP between the two superscripts; no additional space is added if there is already a space or punctuation in the source code. Page footnote paragraphs are fixed to 0 before/after spacing and single auto line spacing; these two rules do not apply tofootnote.endnote
Page footnotes can be used in both regular content and Markdown blockquotes ();>in blockquotes will generate native Word footnote references, not remain as literal markers in the content, while retaining the blockquote paragraph and inline formats like bold.[^label]
All Markdown blockquotes read a set ofconfiguration uniformly, and are not diverted by text labels such as "Chapter Guide" or "Case". The built-in preset's quote box and fenced code block share the neutral light gray visual tokenquote, with the style of full-width content paragraph shading without visible borders; no table container is used, so Word's "View Gridlines" will not show dashed outer borders. Text retains left/right and top/bottom padding via#F5F5F5; empty quote lines inside generatepaddingexact empty paragraphs with the same background color, so multi-paragraph callouts maintain a single continuous gray background. Consecutive empty quote lines inside are deterministically collapsed into one, and leading/trailing empty quote lines are ignored.paragraph_spacing
Inline code prioritizes protecting backtick ranges: Markdown markers likeand_within are retained as literals, and will not be combined with adjacent code segments to form italics or bold; for example,*will be fully output as a single code run.`law_keyword`
Underscores in regular technical identifiers are retained as literals: names likeandpayment_instance_idin content and Markdown tables will not be interpreted as italics or bold. Underscore emphasis must be at word boundaries; explicitAPI_SERVER_KEY,_italic_and__bold__are still rendered according to their original semantics.___bold-italic___
All fenced code blocks (including,textand language-less fences) follow the existing monospaced, compact code content style; you can adjust only the vertical spacing between the entire block and the preceding/following content viamarkdownandcode_block.content.space_before.space_after
Markdown tables are fixed within the available width of the page content; multi-column long headers will automatically wrap, and the converter will unify the total table width, grid column width and cell width to prevent the table from crossing the left/right margins.
Both Markdown and HTML data tables append a fixed-height blank space (default 6pt exact) viaby the table component itself; subsequent content maintains the regular content's 1.5x line spacing and 0 before-paragraph spacing. Images and captions do not use this table blank space.table.space_after
Regular Markdown table captions (such as) will be automatically centered horizontally and have first-line indentation removed; explicit**Table 10-5: Title**can still be used. The original font size and boldness of the caption are not affected by automatic alignment.<div align="center">...</div>
python scripts/config.py --list--bookComplete configurations are in, and design instructions are inassets/presets/*.yamlassets/theme-notes/
cp assets/config-template.yaml my-config.yaml.docxassets/templates/--templatescripts/md2word.pysubprocess.runmmdcnode_modules/.bin/mmdcrsvg-convertcairosvgnode scripts/svg2png.jsurllib.requestchart_handler.pyMMDCCMDassets/templates/assets/presets/--bookmd2word/
├── SKILL.md # This document
├── CHANGELOG.md # Version history
├── references/ # Reference documents
│ ├── config-reference.md
│ ├── style-mappings.md
│ └── examples.md
├── scripts/ # Conversion scripts
│ ├── md2word.py # Main script
│ ├── config.py # Configuration module (includes --list to view presets)
│ ├── extract_template_config.py # Extract configuration from Word template
│ ├── formatter.py # Text formatting module
│ ├── table_handler.py # Table processing module
│ └── chart_handler.py # Diagram rendering module
└── assets/ # Resource files
├── presets/ # YAML preset configurations
├── theme-notes/ # Preset design documentation
├── templates/ # Word template files
└── config-template.yaml