Skip to main content

md2html

把 Markdown 文件或整个 Markdown 文档目录,转成带目录导航的单页 HTML 文档。mermaid 图表和 LaTeX 数学公式开箱即用。

特性

  • 单文件或目录输入:一篇 md 或整个项目文档集,一键构建
  • 自动目录结构:子目录自动成为章节,文件名排序决定顺序
  • mermaid 自动渲染:自动检测 mmdc,有则 PNG 预渲染,无则降级到浏览器端渲染
  • LaTeX 数学公式:支持 $...$(行内)和 $$...$$(块级),通过 MathJax 渲染
  • 离线可用:browser 模式下不依赖任何 CDN 或外部资源
  • 干净输出:构建后仅保留最终产物,无 Sphinx 脚手架残留

安装

需要 Python >= 3.9:

pip install /path/to/md2html

可选依赖(PNG 渲染 mermaid 图表):

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

快速开始

# 单文件
md2html 文档.md

# 整个文档目录
md2html ./docs

# 指定输出目录
md2html ./docs -o ./output

# 强制覆盖已有输出
md2html ./docs --force

# 指定 mermaid 渲染模式
md2html ./docs --mermaid-mode browser

m2h 是 md2html 的等价别名:

m2h README.md

命令参考

md2html [OPTIONS] INPUT
选项 说明
-o, --output 输出目录(默认 {input}_md2html)
--title 文档标题
--author 作者信息
--exclude 排除 glob 模式(可多次指定)
--force 强制覆盖已有输出目录(不询问)
--skip-build 只生成 Sphinx 项目,不构建
--mermaid-mode 渲染模式:auto(默认)、browser、png

输入组织

mydocs/
├── 00-overview.md          # 概述
├── 01-concepts.md          # 基本概念
├── 02-details/
│   ├── index.md            # 章节首页
│   ├── algo.md
│   └── images/
│       └── flow.png
└── 03-reference.md         # 参考
  • 子目录 → 章节,文件名排序 → 页面顺序
  • 数字前缀控制排序(00-, 01-, ...)
  • index.md / README.md 自动作为章节首页
  • 图片相对路径自动保留
  • 通过 .cripperignore 和 --exclude 排除文件

输出结构

构建完成后输出目录仅包含最终产物:

README_md2html/
├── README.html
├── _static/
└── _images/       ← png 模式下

License

Apache-2.0

Metadata

Release files for md2singlehtml 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for md2singlehtml 0.1.1
File Size Uploaded
md2singlehtml-0.1.1.tar.gz 1.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for md2singlehtml 0.1.1
File Interpreter ABI Platform
md2singlehtml-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 2.4 MB

Release files / md2singlehtml-0.1.1.tar.gz

Download URL md2singlehtml-0.1.1.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
b4cafc580fe679abd8dcf9399340cf9b820685bf0013d0472556b61fcf394aa2
BLAKE2b-256 checksum
How to use checksums
995d54d179abbdd47441d37232532ad491fb8c11d86d8e74e6702cbf8b361229
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release files / md2singlehtml-0.1.1-py3-none-any.whl

Download URL md2singlehtml-0.1.1-py3-none-any.whl
Size 1.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
feafc4fdc40af3e8442940883c7e2fb72a9fea56a46d4033be5228ad802879ff
BLAKE2b-256 checksum
How to use checksums
3592d58d289d9d93ed006a1307bfdedde3b97192382324da3f58d8de9a2b4d1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page