Star 历史趋势
数据来源: GitHub API · 生成自 Stargazers.cn
README.md

📚 EPUB Book Generator

把你的 Markdown 文章一键生成专业电子书

从博客文章、技术笔记、学习资料生成精美 EPUB 电子书。自动下载图片、完美渲染代码块、生成专业封面,兼容微信读书和 Apple Books。

English | 中文


English

What It Does

Converts Markdown files into professional EPUB ebooks with:

  • ✅ Auto-downloads remote images (http/https URLs)
  • ✅ SVG to PNG conversion (perfect for web articles)
  • ✅ Code blocks, tables, lists rendering
  • ✅ Professional cover generation (SVG/HTML)
  • ✅ Image compression (PNG→JPEG)
  • ✅ WeChat Reading & Apple Books compatible

Installation

Option 1: npx (Recommended)

npx skills add joeseesun/qiaomu-epub-book-generator

Option 2: Git Clone

git clone https://github.com/joeseesun/qiaomu-epub-book-generator.git ~/.claude/skills/qiaomu-epub-book-generator

Prerequisites

  • Python 3.8+ (python3 --version)
  • pip installed (pip3 --version)
  • Install dependencies:
    pip install ebooklib markdown Pillow playwright beautifulsoup4 playwright install chromium
    Verify: python3 -c "import ebooklib; print('OK')"

Quick Start

Step 1: Prepare Markdown files

mkdir ~/my-articles # Put your .md files in ~/my-articles/

Step 2: Generate EPUB

Tell Claude Code:

  • "Generate EPUB from ~/my-articles/"
  • "Create ebook from my blog posts"
  • "Make EPUB with title 'My Tech Blog' and author 'John Doe'"

Or run directly:

cd ~/.claude/skills/qiaomu-epub-book-generator/scripts python3 gen_epub_enhanced.py ~/my-articles ~/output.epub \ --title "My Tech Blog" \ --author "John Doe" \ --cover-svg

Step 3: Verify output

ls -lh ~/output.epub # Should see file size (e.g., 2.5 MB)

Usage Examples

Basic (auto-detect title from first article)

python3 gen_epub_enhanced.py ~/articles ~/book.epub

With SVG cover (KDP standard 1600x2560)

python3 gen_epub_enhanced.py ~/articles ~/book.epub \ --title "My Book" \ --subtitle "A Collection of Essays" \ --author "Your Name" \ --cover-svg \ --cover-theme tech \ --cover-layout minimal

With custom cover image

python3 gen_epub_enhanced.py ~/articles ~/book.epub \ --title "My Book" \ --author "Your Name" \ --cover ~/my-cover.jpg

Custom image quality

python3 gen_epub_enhanced.py ~/articles ~/book.epub \ --image-quality 95 \ --image-width 1200

Parameters

ParameterDescriptionDefault
input_dirDirectory with Markdown filesRequired
output_fileOutput EPUB pathRequired
--titleBook titleFrom first article
--authorAuthor name(s), separate with /From frontmatter
--subtitleSubtitle for coverNone
--languageLanguage codezh
--coverCover image pathNone
--cover-svgGenerate SVG cover (KDP 1600x2560)False
--cover-htmlGenerate HTML coverFalse
--cover-themeCover theme: tech, business, design, literature, science, personalAuto-detect
--cover-layoutSVG layout: minimal, classic, modernminimal
--image-qualityJPEG quality (1-100)88
--image-widthMax image width (pixels)1000

Cover Themes

ThemeKeywordsStyle
techprogramming, AI, code, algorithmDeep navy + cyan
businessstartup, marketing, growth, productDeep blue + gold
designdesign, UI/UX, visual, brandDeep purple + pink
literaturenovel, poetry, story, philosophyNavy blue + warm yellow
sciencescience, physics, research, theoryTeal + mint
personalgrowth, learning, notes, reflectionDeep purple + peach

Real-World Example

Tw93 Tech Blog → EPUB

# 4 articles, 53 images (33 SVG→PNG), 2.9 MB output python3 gen_epub_enhanced.py /tmp/tw93_articles ~/Tw93-Tech.epub \ --title "Tw93技术文集" \ --subtitle "Claude、Agent、LLM 与学习方法论" \ --author "Tw93" \ --cover ~/cover.png \ --image-quality 88 \ --image-width 1000

Troubleshooting

ProblemSolution
ModuleNotFoundError: No module named 'ebooklib'Run pip install ebooklib markdown Pillow
playwright._impl._api_types.Error: Executable doesn't existRun playwright install chromium
Code blocks show red boxes around special charactersFixed in v2.0+ (regex removes Pygments error borders)
Images not embeddedCheck image URLs are valid http/https or local paths
SVG conversion failsEnsure Playwright installed: pip install playwright && playwright install chromium
EPUB file too largeReduce --image-quality (e.g., 75) or --image-width (e.g., 800)

⚠️ Notes

  • Playwright required for SVG conversion and cover generation
  • Image download: Remote images are downloaded and embedded automatically
  • File size: Typical 2-5 MB for 10-20 articles with images
  • Compatibility: Tested on WeChat Reading, Apple Books, Calibre

Credits


中文

核心价值

把 Markdown 文章转换成专业 EPUB 电子书,支持:

  • ✅ 自动下载远程图片(http/https URL)
  • ✅ SVG 自动转 PNG(完美支持网页文章)
  • ✅ 完整渲染代码块、表格、列表
  • ✅ 专业封面生成(SVG/HTML)
  • ✅ 图片智能压缩(PNG→JPEG)
  • ✅ 兼容微信读书和 Apple Books

安装方式

方式 1:npx(推荐)

npx skills add joeseesun/qiaomu-epub-book-generator

方式 2:Git 克隆

git clone https://github.com/joeseesun/qiaomu-epub-book-generator.git ~/.claude/skills/qiaomu-epub-book-generator

前置条件

  • Python 3.8+ (python3 --version 检查)
  • pip 已安装 (pip3 --version 检查)
  • 安装依赖:
    pip install ebooklib markdown Pillow playwright beautifulsoup4 playwright install chromium
    验证:python3 -c "import ebooklib; print('OK')"

快速开始

第 1 步:准备 Markdown 文件

mkdir ~/my-articles # 把你的 .md 文件放到 ~/my-articles/ 目录

第 2 步:生成 EPUB

直接对 Claude Code 说:

  • "从 ~/my-articles/ 生成 EPUB"
  • "把我的博客文章做成电子书"
  • "生成 EPUB,书名《我的技术博客》,作者张三"

或直接运行命令:

cd ~/.claude/skills/qiaomu-epub-book-generator/scripts python3 gen_epub_enhanced.py ~/my-articles ~/output.epub \ --title "我的技术博客" \ --author "张三" \ --cover-svg

第 3 步:验证输出

ls -lh ~/output.epub # 应该看到文件大小(如 2.5 MB)

使用示例

基础用法(自动从第一篇文章提取标题)

python3 gen_epub_enhanced.py ~/articles ~/book.epub

生成 SVG 封面(KDP 标准 1600x2560)

python3 gen_epub_enhanced.py ~/articles ~/book.epub \ --title "我的书" \ --subtitle "文章合集" \ --author "你的名字" \ --cover-svg \ --cover-theme tech \ --cover-layout minimal

使用自定义封面图片

python3 gen_epub_enhanced.py ~/articles ~/book.epub \ --title "我的书" \ --author "你的名字" \ --cover ~/my-cover.jpg

自定义图片质量

python3 gen_epub_enhanced.py ~/articles ~/book.epub \ --image-quality 95 \ --image-width 1200

参数说明

参数说明默认值
input_dirMarkdown 文件目录必填
output_file输出 EPUB 文件路径必填
--title书名从第一篇文章提取
--author作者(多个用 / 分隔)从 frontmatter 提取
--subtitle封面副标题
--language语言代码zh
--cover封面图片路径
--cover-svg生成 SVG 封面(KDP 1600x2560)False
--cover-html生成 HTML 封面False
--cover-theme封面主题:tech, business, design, literature, science, personal自动检测
--cover-layoutSVG 布局:minimal, classic, modernminimal
--image-qualityJPEG 压缩质量 (1-100)88
--image-width图片最大宽度(像素)1000

封面主题

主题关键词风格
tech编程、AI、代码、算法深蓝 + 青色
business创业、营销、增长、产品深蓝 + 金色
design设计、UI/UX、视觉、品牌深紫 + 粉色
literature小说、诗歌、故事、哲学海军蓝 + 暖黄
science科学、物理、研究、理论青绿 + 薄荷
personal成长、学习、笔记、反思深紫 + 桃色

真实案例

Tw93 技术博客 → EPUB

# 4 篇文章,53 张图片(33 SVG→PNG),2.9 MB 输出 python3 gen_epub_enhanced.py /tmp/tw93_articles ~/Tw93技术文集.epub \ --title "Tw93技术文集" \ --subtitle "Claude、Agent、LLM 与学习方法论" \ --author "Tw93" \ --cover ~/cover.png \ --image-quality 88 \ --image-width 1000

常见问题

问题解决方法
ModuleNotFoundError: No module named 'ebooklib'运行 pip install ebooklib markdown Pillow
playwright._impl._api_types.Error: Executable doesn't exist运行 playwright install chromium
代码块特殊字符有红框v2.0+ 已修复(正则移除 Pygments 错误边框)
图片没有嵌入检查图片 URL 是否有效(http/https 或本地路径)
SVG 转换失败确保安装 Playwright:pip install playwright && playwright install chromium
EPUB 文件太大降低 --image-quality(如 75)或 --image-width(如 800)

⚠️ 注意事项

  • 需要 Playwright:用于 SVG 转换和封面生成
  • 图片下载:远程图片会自动下载并嵌入
  • 文件大小:10-20 篇文章带图片通常 2-5 MB
  • 兼容性:已在微信读书、Apple Books、Calibre 测试

致谢


📱 关注作者

如果这个项目对你有帮助,欢迎关注我获取更多技术分享:

  • X (Twitter): @vista8
  • 微信公众号「向阳乔木推荐看」:

向阳乔木推荐看公众号二维码

许可证

MIT License

关于 About

从 Markdown 文件生成专业 EPUB 电子书,支持封面、配图压缩、目录生成,兼容微信读书

语言 Languages

Python100.0%

提交活跃度 Commit Activity

代码提交热力图
过去 52 周的开发活跃度
5
Total Commits
峰值: 5次/周
Less
More

核心贡献者 Contributors