Markdown to GOST-style A4 PDF converter with Mermaid support.
Project description
md2pdf
md2pdf converts Markdown files into A4 portrait PDF documents with a restrained layout close to ГОСТ Р 7.32 conventions: serif font, 14 pt body text, 1.5 line spacing, 1.25 cm paragraph indent, simple tables, code blocks, Mermaid diagrams and centered page numbers.
The project is intentionally small. It is useful for course work, project reports, internal technical notes and other documents where predictable PDF output matters more than full Markdown compatibility.
Features
| Feature | Behavior | Notes |
|---|---|---|
| Text | Serif font, 14 pt, justified paragraphs | First-line indent is 1.25 cm |
| Headings | Bold serif headings | The first H1 is centered as a title |
| Lists | Dash marker with a fixed left indent | Supports flat - lists |
| Tables | Plain grid with repeated header rows | Best for simple pipe tables |
| Code blocks | Monospace-style framed block using the document font | Long lines are preserved |
| Mermaid | Renders diagrams to PNG before inserting into PDF | Built-in renderer covers common diagram types |
| Pages | A4 portrait with 30/10/20/20 mm margins | Page number is centered in the footer |
Requirements
- Python 3.11 or newer.
- Node.js 20 or newer if you want Mermaid CLI rendering.
- A compatible serif font:
- Times New Roman on macOS;
- Times New Roman in the user font folder on macOS;
- Microsoft Core Fonts or DejaVu Serif on Linux.
The converter can still render supported Mermaid diagrams when Mermaid CLI is unavailable or when its browser backend fails. Set MD2PDF_STRICT_MERMAID=1 if you want Mermaid CLI failures to stop the build.
Installation
For regular use from a checkout:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .
Install Mermaid CLI support:
npm install
For development, install the extra tools:
python -m pip install -e ".[dev]"
Check local dependencies:
md2pdf --check-deps
Usage
Build the repository README:
PYTHONPATH=src python3 -m md2pdf README.md README.pdf
Build the example document:
PYTHONPATH=src python3 -m md2pdf examples/example.md examples/example.pdf
After editable installation, the console entry point is available:
md2pdf README.md README.pdf
The input and output arguments are optional. Without arguments, the tool reads README.md and writes README.pdf in the current directory.
Useful options:
md2pdf --version
md2pdf --check-deps
md2pdf input.md output.pdf --strict-mermaid
md2pdf input.md output.pdf --temp-dir .md2pdf/custom
md2pdf input.md output.pdf --font-size 13 --line-height 1.45
md2pdf input.md output.pdf --margins 30,10,20,20
md2pdf input.md output.pdf --quiet
Supported Markdown
The parser supports the practical subset used by this project:
- headings from
#to######; - paragraphs separated by blank lines;
- flat unordered lists written as
- item; - simple pipe tables;
- fenced code blocks;
- fenced Mermaid blocks.
Complex Markdown extensions are not implemented: nested lists, footnotes, raw HTML blocks, escaped table pipes and advanced link syntax should be simplified before conversion.
Mermaid
Mermaid blocks are rendered in this order:
- Mermaid CLI through the local
node_modules/.bin/mmdcor a globalmmdc. - Built-in renderers for supported diagram families when Mermaid CLI is unavailable or fails outside strict mode.
- Plain code block output when the diagram type is unsupported and no renderer succeeds.
Supported built-in families:
flowchart;sequenceDiagram;stateDiagram;xychart-beta.
Development
More details are available in docs/development.md. Usage examples are collected in docs/usage.md.
Run the local quality gate:
python -m ruff check .
python -m pytest -q
npm run pdf
npm run example
The npm shortcut runs the same checks:
npm run check
Project files:
| Path | Purpose |
|---|---|
src/md2pdf/config.py |
Shared defaults, version, fonts and runtime flags |
src/md2pdf/markdown.py |
Markdown cleanup, tables and block helpers |
src/md2pdf/mermaid.py |
Mermaid CLI integration and built-in renderers |
src/md2pdf/pdf.py |
ReportLab PDF generation |
src/md2pdf/core.py |
Compatibility facade for older imports |
src/md2pdf/cli.py |
CLI argument parsing |
src/md2pdf/__main__.py |
python -m md2pdf entry point |
tests/test_md2pdf.py |
Unit and smoke tests |
examples/example.md |
Example input document |
examples/example.pdf |
Generated example output |
README.pdf |
Generated README output |
CONTRIBUTING.md |
Contributor guide |
SECURITY.md |
Security policy |
CHANGELOG.md |
Release notes |
docs/usage.md |
CLI usage notes |
docs/development.md |
Development workflow |
docs/release.md |
Release workflow |
PDF artifacts are committed intentionally. Update README.pdf and examples/example.pdf only when README, examples or rendering behavior changes.
Troubleshooting
Font not found
Install Times New Roman, Microsoft Core Fonts or DejaVu Serif. The tool checks common macOS and Linux font paths.
Mermaid CLI fails to launch a browser
This can happen in sandboxed environments or CI runners. By default, the converter uses built-in renderers for supported diagram types. Use --strict-mermaid to fail fast instead.
Diagram layout differs from Mermaid CLI
Built-in renderers are intentionally simple black-and-white renderers. They keep the PDF build usable, but they are not a complete Mermaid implementation.
Markdown output is missing advanced formatting
The converter is not a full Markdown engine. Simplify unsupported Markdown features or add a focused parser feature with tests.
License
MIT. See LICENSE.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md2pdf_gost-1.0.3.tar.gz.
File metadata
- Download URL: md2pdf_gost-1.0.3.tar.gz
- Upload date:
- Size: 176.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
005e152d9011d9513b920b0ea5f6ee909428500ee9a450c490d18b6e534614c2
|
|
| MD5 |
c18ab3879a387ce430c1e10bb6ef2c5f
|
|
| BLAKE2b-256 |
48239eb05cd784eb6b05d04d8a3d08343cd022d6811065e3e749df1ec88534a3
|
Provenance
The following attestation bundles were made for md2pdf_gost-1.0.3.tar.gz:
Publisher:
release.yml on alyldas/md2pdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2pdf_gost-1.0.3.tar.gz -
Subject digest:
005e152d9011d9513b920b0ea5f6ee909428500ee9a450c490d18b6e534614c2 - Sigstore transparency entry: 1508121357
- Sigstore integration time:
-
Permalink:
alyldas/md2pdf@f2e068630776f5c7bc02111cec8feed517cd55bb -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/alyldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f2e068630776f5c7bc02111cec8feed517cd55bb -
Trigger Event:
push
-
Statement type:
File details
Details for the file md2pdf_gost-1.0.3-py3-none-any.whl.
File metadata
- Download URL: md2pdf_gost-1.0.3-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bcb44ab83209f59fec51dc36f369c93db7134bb2d8c91c5e46aaf6ba53afb81
|
|
| MD5 |
8ade7b8be0e13c5ba5fe5d82ea7b771a
|
|
| BLAKE2b-256 |
d47fc651e55ada6ac72c3949586e8053125a7d88ff8e057096fe7458ccceb83b
|
Provenance
The following attestation bundles were made for md2pdf_gost-1.0.3-py3-none-any.whl:
Publisher:
release.yml on alyldas/md2pdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2pdf_gost-1.0.3-py3-none-any.whl -
Subject digest:
8bcb44ab83209f59fec51dc36f369c93db7134bb2d8c91c5e46aaf6ba53afb81 - Sigstore transparency entry: 1508121629
- Sigstore integration time:
-
Permalink:
alyldas/md2pdf@f2e068630776f5c7bc02111cec8feed517cd55bb -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/alyldas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f2e068630776f5c7bc02111cec8feed517cd55bb -
Trigger Event:
push
-
Statement type: