EPUB电子书生成器。Use when user wants to create professional EPUB ebooks from Markdown, text, or structured content. Supports chapters, TOC, cover image, metadata. 电子书、EPUB制作。
专业EPUB电子书生成器,支持Markdown转EPUB、多章节、目录、封面。
python
import os
from ebooklib import epub
class EpubGenerator:
def init(self, title, author=Unknown, language=zh):
self.book = epub.EpubBook()
self.book.set_title(title)
self.book.set_language(language)
self.book.add_author(author)
self.chapters = []
def add_chapter(self, title, content, filename=None):
添加章节
if filename is None:
filename = fchapter_{len(self.chapters)+1}.xhtml
chapter = epub.EpubHtml(title=title, file_name=filename)
chapter.content = f
self.book.add_item(chapter)
self.chapters.append(chapter)
return chapter
def addmarkdownchapters(self, markdown_content):
将Markdown拆分为章节
sections = markdown_content.split(\n# )
for i, section in enumerate(sections):
if not section.strip():
continue
lines = section.split(\n)
title = lines[0].replace(#, ).strip()
content =
.join(lines[1:])
self.add_chapter(title, content)
def addcover(self, imagepath):
添加封面图片
with open(image_path, rb) as f:
cover_image = f.read()
self.book.setcover(cover.jpg, coverimage)
def set_toc(self):
生成目录
self.book.toc = self.chapters
# 添加导航
self.book.add_item(epub.EpubNcx())
self.book.add_item(epub.EpubNav())
def add_spine(self):
设置阅读顺序
self.book.spine = [nav] + self.chapters
def save(self, output_path):
保存EPUB文件
self.set_toc()
self.add_spine()
epub.writeepub(outputpath, self.book, {})
return output_path
此处为内容...
) gen.add_chapter(第二章,更多内容...
) gen.save(output.epub)用户: 帮我把这篇Markdown做成电子书
助手: 使用 EpubGenerator 生成EPUB
用户: 创建一本3章的电子书
助手: 分章生成EPUB
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 epub-studio-1776014894 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 epub-studio-1776014894 技能
skillhub install epub-studio-1776014894
文件大小: 2.71 KB | 发布时间: 2026-4-13 10:11