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.3.tar.gz (15.8 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.3-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: md_to_docx-0.1.3.tar.gz
  • Upload date:
  • Size: 15.8 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.3.tar.gz
Algorithm Hash digest
SHA256 ceafea45332018c9794a7cc6f0adb0e59a5dd92da2ec9708c2d1719d8ffc85fd
MD5 515ea4da7550b37e8d5f3c7b277ac4e4
BLAKE2b-256 66b5085cf2eb63c8afbe0d5a219bff5f9145ef704a5bb82224538b9abff89c64

See more details on using hashes here.

File details

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

File metadata

  • Download URL: md_to_docx-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 803c32c361c1335a434c3ce4c6f0d57d8df11e5cd1ec98c14130a7d56bcb20da
MD5 175be68114b791fe693c4175599456a9
BLAKE2b-256 5b24dab133c4294dac5648e4e25cbc0f186b4cdf5ef7d55ef33d716e656fa068

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