markdown-to-epub
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesemarkdown-to-epub Skill
markdown-to-epub Skill
把 Markdown 手稿(含本地图片)稳定构建为 EPUB:规范化图片引用、拷贝资产到可重复的构建目录、调用 Calibre 转换,并输出可核查报告。
ebook-convertStably build Markdown manuscripts (including local images) into EPUB: Normalize image references, copy assets to a reproducible build directory, call Calibre for conversion, and output a verifiable report.
ebook-convertWhen to Use This Skill
When to Use This Skill
触发条件(满足其一即可):
- 需要把一份(或多份)Markdown 手稿打包交付为 EPUB。
- 图片引用混乱(URL 编码、路径飘忽、扩展名不可信如 ),需要自动归一化。
.bin/.idunno - 需要在转换后做最基本的 EPUB 包结构检查(OPF/NCX/NAV、图片数量等)。
Trigger conditions (meet any one):
- Need to package one (or multiple) Markdown manuscripts into EPUB for delivery.
- Image references are messy (URL encoded, unstable paths, untrusted extensions like ), requiring automatic normalization.
.bin/.idunno - Need to perform basic EPUB package structure checks (OPF/NCX/NAV, number of images, etc.) after conversion.
Not For / Boundaries
Not For / Boundaries
- 不负责生成/改写正文内容(不会修改源手稿,只在构建目录里产出规范化版本)。
- 不下载远程图片(/
http(s)引用会保持原样)。data: - 不替代真正的排版/校对流程(这里只做可交付构建与结构验证)。
- Does not generate/rewrite content (will not modify the source manuscript, only produce a normalized version in the build directory).
- Does not download remote images (references with /
http(s)will remain unchanged).data: - Does not replace real typesetting/proofreading processes (only delivers build and structure verification here).
Quick Start
Quick Start
从仓库根目录执行(推荐 ):
python3bash
python3 skills/05-生产力/markdown-to-epub/scripts/build_epub.py \
--input-md "./book.md" \
--output-epub "./book.epub" \
--title "Book Title" \
--authors "Author Name" \
--language "zh-CN"脚本会创建构建工作区(默认 ),包含:
build_epub/book.normalized.md- :拷贝后的图片(会按真实文件签名推断扩展名)
assets/ conversion.logreport.json
Execute from the root directory of the repository (recommended ):
python3bash
python3 skills/05-生产力/markdown-to-epub/scripts/build_epub.py \
--input-md "./book.md" \
--output-epub "./book.epub" \
--title "Book Title" \
--authors "Author Name" \
--language "zh-CN"The script will create a build workspace (default ) containing:
build_epub/book.normalized.md- : Copied images (extensions will be inferred based on real file signatures)
assets/ conversion.logreport.json
依赖
Dependencies
- 需要安装 Calibre,并确保 在
ebook-convert中(或用PATH指定路径)。--ebook-convert-bin
- Calibre needs to be installed, and ensure is in the
ebook-convert(or specify the path withPATH).--ebook-convert-bin
Missing Asset Recovery
Missing Asset Recovery
如果 Markdown 里引用了图片但文件找不到,可以提供一个 JSON 映射表(按「basename」匹配):
json
{
"missing-file.idunno": "replacement-file.idunno"
}然后重跑(示例):
bash
python3 skills/05-生产力/markdown-to-epub/scripts/build_epub.py \
--input-md "./book.md" \
--output-epub "./book.epub" \
--fallback-map "./fallback-map.json"If images referenced in Markdown cannot be found, you can provide a JSON mapping table (matching by "basename"):
json
{
"missing-file.idunno": "replacement-file.idunno"
}Then re-run (example):
bash
python3 skills/05-生产力/markdown-to-epub/scripts/build_epub.py \
--input-md "./book.md" \
--output-epub "./book.epub" \
--fallback-map "./fallback-map.json"Operational Rules
Operational Rules
- 优先使用 ;缺失时明确报错并快速失败。
ebook-convert - 源手稿只读;所有输出写入 。
build_dir/ - TOC 以标题层级()为准。
h1/h2/h3 - 缺失资产必须显式报告;严格模式下不允许静默跳过。
- 命令保持非交互式。
- Prioritize using ; explicitly report an error and fail fast if missing.
ebook-convert - Source manuscripts are read-only; all outputs are written to .
build_dir/ - TOC is based on title levels ().
h1/h2/h3 - Missing assets must be explicitly reported; silent skipping is not allowed in strict mode.
- Commands remain non-interactive.
Script Interface
Script Interface
scripts/build_epub.py- (必选):源 Markdown 路径
--input-md - (可选):输出 EPUB 路径,默认
--output-epub<input-stem>.epub - (可选):解析图片引用的根目录,默认使用 Markdown 所在目录
--source-root - (可选):构建工作区目录,默认
--build-dir<cwd>/build_epub - (可选):JSON 映射(缺失图片 basename → 替换 basename)
--fallback-map - /
--title/--authors:传给--language的元数据ebook-convert - :输入 Markdown 编码,默认
--input-encodingutf-8 - :严格模式(有任何本地图片无法解析则失败,默认开启)
--strict-missing - :关闭严格模式(保留未解析链接,继续转换)
--no-strict-missing - :
--ebook-convert-bin可执行文件名/路径,默认ebook-convertebook-convert
Parameters for :
scripts/build_epub.py- (required): Path to source Markdown
--input-md - (optional): Path to output EPUB, default is
--output-epub<input-stem>.epub - (optional): Root directory for resolving image references, default is the directory where the Markdown file is located
--source-root - (optional): Build workspace directory, default is
--build-dir<cwd>/build_epub - (optional): JSON mapping (missing image basename → replacement basename)
--fallback-map - /
--title/--authors: Metadata passed to--languageebook-convert - : Encoding of input Markdown, default is
--input-encodingutf-8 - : Strict mode (fails if any local image cannot be resolved, enabled by default)
--strict-missing - : Disable strict mode (retain unresolved links and continue conversion)
--no-strict-missing - : Executable name/path of
--ebook-convert-bin, default isebook-convertebook-convert
Validation Checklist
Validation Checklist
- 确认 EPUB 文件生成且大小不是「几 KB 的空壳」。
- 确认 EPUB(zip)内包含 OPF 与 NCX/NAV。
- 确认 EPUB 内图片数量不低于对手稿的预期。
- 严格模式下确认 的
report.json为空。missing_images
- Confirm that the EPUB file is generated and its size is not an "empty shell of a few KB".
- Confirm that the EPUB (zip) contains OPF and NCX/NAV.
- Confirm that the number of images in the EPUB is not lower than expected from the manuscript.
- In strict mode, confirm that in
missing_imagesis empty.report.json