DOC Converter

Overview

A user may ask you to convert Markdown files to DOCX format, including handling embedded diagrams. This skill provides a workflow for managing the conversion process using the md_to_docx.py script.

Workflow

1. Identify conversion requirements

  • Determine the workspace root directory
  • Verify the Python script exists at script/md_to_docx.py
  • Verify the source markdown file exists
  • Check for diagram dependencies (SVG/PNG files in diagrams folder)
  • Confirm output path and naming

2. Execute conversion

Run the conversion script using the run_in_terminal tool:

python script/md_to_docx.py

3. Verify results

  • Check that the DOCX file was created successfully
  • Report any errors or warnings from the conversion process
  • Confirm diagram insertions completed

Conversion Rules

  • The script expects markdown files in docs/ folder
  • Diagrams should be in docs/diagrams/ folder
  • SVG files are automatically converted to PNG for DOCX insertion
  • Mermaid code blocks are replaced with corresponding diagram images
  • Default conversion: docs/Software-Architecture-AutoReceipt-zh.mddocs/Software-Architecture-AutoReceipt-zh.docx

Error Handling

If conversion fails, follow these diagnostic steps:

  1. Verify Python script path:
  2. Check if script/md_to_docx.py exists
  3. If not found, use read_file or list_dir to locate the correct path

  4. Check Python environment:

  5. Verify python-docx is installed: pip list | Select-String "python-docx"
  6. If missing, suggest: pip install python-docx

  7. Verify input files:

  8. Confirm markdown file exists
  9. Check diagram files are present

  10. Check optional dependencies:

  11. Test cairosvg availability for SVG→PNG conversion
  12. If missing and needed, suggest: pip install cairosvg

  13. Path resolution:

  14. Ensure working directory is the workspace root
  15. Use absolute paths to avoid path resolution issues

Dependencies

Required dependencies:

  • python-docx
  • cairosvg (optional, for SVG conversion)