Skip to main content

Convert Markdown to DOCX with support for Mermaid diagrams

Project description

MD_TO_DOCX

A tool for converting Markdown files to DOCX format with support for Mermaid diagrams and code block formatting.

Features

  • Convert Markdown files to DOCX format
  • Support for rendering Mermaid diagrams as images
  • Code block formatting with borders and language highlighting
  • Support for tables, lists, and other Markdown elements
  • Detailed debugging functionality

Installation

From PyPI

pip install md-to-docx

From Source

git clone https://github.com/yourusername/md-to-docx.git
cd md-to-docx
pip install -e .

Usage

Command Line

# Basic usage
md-to-docx input.md -o output.docx

# With debugging enabled
md-to-docx input.md -o output.docx -d

As a Python Library

from md_to_docx import md_to_docx

# Convert Markdown content to DOCX
result = md_to_docx(markdown_content, "output.docx")
print(f"Output file: {result}")

As an MCP Server

# Start the MCP server
python -m md_to_docx.server

Then you can use it in your MCP client code:

from mcp.client import Client

client = Client()
md_content = "# Hello World\n\nThis is a test."
result = await client.md_to_docx_tool(md_content=md_content)
print(f"Output file: {result}")

Debugging Code Block Issues

If you encounter issues with code blocks, you can use these debugging features:

  1. Enable debug mode:

    md-to-docx input.md -o output.docx -d
    

    This will show detailed information about code block extraction and processing.

  2. Use as a library with debug mode:

    from md_to_docx import md_to_docx
    
    result = md_to_docx(markdown_content, "output.docx", debug_mode=True)
    

Common Issues

Code Blocks Not Displaying Correctly

If code blocks aren't displaying correctly, it might be due to:

  1. Special characters in the code that affect the regex pattern matching
  2. Improper code block formatting (e.g., missing newlines)
  3. Incorrect handling of line breaks in the code

Mermaid Diagrams Not Rendering

If Mermaid diagrams aren't rendering correctly, it might be due to:

  1. Mermaid CLI not being installed
  2. Network connection issues preventing access to the Mermaid.ink API
  3. Syntax errors in the Mermaid diagram code

Advanced Usage

Customizing Code Block Formatting

You can modify the format_code_block function in the source code to customize code block formatting, such as changing fonts, sizes, or border styles.

Adding New Markdown Extensions

You can add new Markdown extensions to support additional Markdown features by modifying the md_to_docx function:

from md_to_docx import md_to_docx
from md_to_docx.core import format_code_block

# Your custom implementation here

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

md_to_docx-0.1.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

md_to_docx-0.1.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file md_to_docx-0.1.1.tar.gz.

File metadata

  • Download URL: md_to_docx-0.1.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for md_to_docx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cd31a26bee8a70b79f525e3dcaaf0bc1d7f273ac0e8005e5fc4ab75f84353c90
MD5 57720fe6d234d80b6428db486e729fda
BLAKE2b-256 31f61844f409a14ceb6368fd2d8dbed419fc61e0440909ba5bfa925c2df6d992

See more details on using hashes here.

File details

Details for the file md_to_docx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: md_to_docx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for md_to_docx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 059e6c498e052cf9d530707f702ee058924dd01c4874699f0d2edbe878b136f3
MD5 9476f8467f20c9567640394e3e7a72f6
BLAKE2b-256 e21e2e340f5fb298cd77b0f299cd78cdab74b9b24473340d04f92e5d29b13086

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page