Skip to main content

Convert Markdown to PDF with Japanese support and MermaidJS diagrams

Project description

gospelo-md2pdf

Convert Markdown to PDF with Japanese support and MermaidJS diagrams.

Features

  • Japanese Text Support: Full support for Japanese fonts (Noto Sans CJK JP, Hiragino Sans, Yu Gothic)
  • MermaidJS Diagrams: Automatically renders Mermaid diagrams as PNG images
  • Custom CSS: Use your own stylesheets or the built-in professional style
  • Markdown Extensions: Tables, fenced code blocks, TOC, metadata, and more
  • Special HTML Classes: Summary boxes, warnings, pros/cons sections, page breaks
  • Agent Skills: Built-in support for AI coding assistants (Claude Code, VS Code Copilot)

Installation

pip install gospelo-md2pdf

System Dependencies

WeasyPrint requires system libraries. Install them first:

macOS:

brew install pango glib gdk-pixbuf libffi

Ubuntu/Debian:

sudo apt install libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0

Japanese Fonts (Recommended)

For Japanese text rendering:

macOS:

brew install font-noto-sans-cjk-jp

Ubuntu/Debian:

sudo apt install fonts-noto-cjk

MermaidJS Support (Optional)

To render Mermaid diagrams:

npm install -g @mermaid-js/mermaid-cli

Quick Start

# Basic usage
gospelo-md2pdf report.md

# Specify output file
gospelo-md2pdf report.md output.pdf

# Specify output directory
gospelo-md2pdf report.md -o ./pdf

# Use custom CSS
gospelo-md2pdf report.md --css custom-style.css

# Keep intermediate files for debugging
gospelo-md2pdf report.md --debug

Usage

gospelo-md2pdf <input.md> [output.pdf] [options]

Arguments:
  input.md              Input Markdown file
  output.pdf            Output PDF file (optional)

Options:
  -o, --output-dir DIR  Output directory (default: current directory)
  -c, --css FILE        Custom CSS file
  --debug               Keep intermediate files (HTML, mermaid) in tmp/ directory
  --lang LANG           HTML lang attribute (default: ja)
  -q, --quiet           Suppress output messages
  --verbose             Print verbose output
  -v, --version         Show version
  -h, --help            Show help

Environment Variables

Variable Description Default
MD2PDF_OUTPUT_DIR Output directory Current directory

Note: --output-dir option takes precedence over the environment variable.

Markdown Features

Basic Syntax

# Heading 1
## Heading 2
### Heading 3

Paragraph with **bold** and *italic* text.

- Bullet list
- Another item
  - Nested item

1. Numbered list
2. Another item

> Blockquote

`inline code`

[Link](https://example.com)

Tables

| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| A        | B        | C        |
| D        | E        | F        |

Code Blocks

```python
def hello():
    print("Hello, World!")
```

MermaidJS Diagrams

```mermaid
graph TD
    A[Start] --> B[Process]
    B --> C{Decision}
    C -->|Yes| D[Result A]
    C -->|No| E[Result B]
```

Supported diagram types:

  • Flowcharts (graph TD, graph LR)
  • Sequence diagrams (sequenceDiagram)
  • Class diagrams (classDiagram)
  • State diagrams (stateDiagram-v2)
  • ER diagrams (erDiagram)
  • And all other Mermaid diagram types

Note: Tall diagrams are automatically scaled to fit within a single page (max-height: 700px) while preserving aspect ratio.

Special HTML Classes

Use these HTML classes in your Markdown for special styling:

Summary Box (Green)

<div class="summary">
Important summary points here.
</div>

Warning Box (Orange)

<div class="warning">
Warning message here.
</div>

Info Box (Blue)

<div class="info">
Additional information here.
</div>

Pros/Cons

<div class="pros">
Pros: High scalability
</div>

<div class="cons">
Cons: Initial cost
</div>

Disclaimer

<div class="disclaimer">
This report is for informational purposes only.
</div>

Page Break

<div class="page-break"></div>

Python API

from gospelo_md2pdf import convert_md_to_pdf

# Basic usage
convert_md_to_pdf("report.md")

# With options
convert_md_to_pdf(
    input_file="report.md",
    output_file="output.pdf",
    output_dir="./pdf",
    css_file="custom.css",
    keep_html=True,
    lang="ja",
    verbose=True
)

Troubleshooting

Japanese text not rendering

Check if Japanese fonts are installed:

fc-list :lang=ja | head -5

WeasyPrint library errors on macOS

Set the library path:

export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH

Add to ~/.zshrc for persistence:

echo 'export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH' >> ~/.zshrc
source ~/.zshrc

Mermaid diagrams not rendering

Verify mermaid-cli is installed:

mmdc --version

If not installed:

npm install -g @mermaid-js/mermaid-cli

Requirements

  • Python >= 3.10
  • weasyprint >= 60.0
  • markdown >= 3.5.0
  • System: pango, glib, gdk-pixbuf (see Installation)
  • Optional: @mermaid-js/mermaid-cli (for Mermaid diagrams)

Dependencies and Acknowledgements

This project uses the following open-source libraries. Full license texts are included in the LICENSE file.

Library License Description
WeasyPrint BSD 3-Clause HTML/CSS to PDF converter
Python-Markdown BSD 3-Clause Markdown to HTML converter
Mermaid CLI MIT Diagram rendering (optional)

System Libraries (Dynamically Linked)

Library License Description
Pango LGPL 2.0+ Text rendering
GLib LGPL 2.1+ Core utilities
GDK-Pixbuf LGPL 2.1+ Image loading

Note: System libraries are dynamically linked and not bundled with this package.

Fonts (Recommended)

Font License Description
Noto Sans CJK JP OFL 1.1 Japanese font by Google

Note: Fonts are not bundled with this package. Users install them separately.

License

MIT License - see LICENSE for details.

Author

NoStudio LLC (goro-hayakawa@no-studio.net)

Documentation

Links

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

gospelo_md2pdf-1.1.2.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

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

gospelo_md2pdf-1.1.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file gospelo_md2pdf-1.1.2.tar.gz.

File metadata

  • Download URL: gospelo_md2pdf-1.1.2.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for gospelo_md2pdf-1.1.2.tar.gz
Algorithm Hash digest
SHA256 2f4c760c6ed6bddb163af9d45efee1714dfbbe02df7344a07ab6b12dd7679a03
MD5 5822e5049d64266a6d5cc037177abeb4
BLAKE2b-256 4d23e472e1da658f46547a57615edcb4bbfaf59c56a6d62e33aad662920c9f8c

See more details on using hashes here.

File details

Details for the file gospelo_md2pdf-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: gospelo_md2pdf-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for gospelo_md2pdf-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cec5f29f651d0f979bb29c3255283c79371414224cfbd2c211b178d2fe24ec0a
MD5 264f8381f1662ec430df0a1ae5d00b87
BLAKE2b-256 9450be4b35b4eae30dd897ab79cebb8fe3f4b66929095cf41577d8f2a7bb6f27

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