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.2.tar.gz (14.6 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.2-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: md_to_docx-0.1.2.tar.gz
  • Upload date:
  • Size: 14.6 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.2.tar.gz
Algorithm Hash digest
SHA256 dae4208d87e6757f8040d104d52dec21b605b19c5828f80a25a3c23ac62adf59
MD5 f4e4eb782ef1e0fc74769c4d2e8a3fa1
BLAKE2b-256 3f1e08bdc62828d2f4b3fd2e74869f49b3551a0a6ad6978e458f6e872d5c2c86

See more details on using hashes here.

File details

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

File metadata

  • Download URL: md_to_docx-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4aa289a2d0acc790566a5ed236e86431b02cb4f3e510f369f2513a87cdeba958
MD5 7b90f43348d72ee6bda481a1fdca2c3e
BLAKE2b-256 ce75f30de48405cf031ebb222bc4629cb4c5259c80f09a00416916be23390c3b

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