用于创建epub3文件的简单极简库
mkepub的Python项目详细描述
mkepub
mkepub是创建.epub文件的极简库。
pros:
- 简单易用,极简的api。
- 自动生成目录。
- 支持任何深度的嵌套TOC。
- 支持嵌入图像。
- 正在进行中的图书存储在磁盘上,而不是内存中,启用 创建大型(5000多页,20多个mib)epub文件。
- 遵守EPUB3规范。
- 支持大多数epub元数据,包括语言、主题、 说明和权利。
cons:
- 不支持自定义页文件名或目录结构。
- 不支持读取或编辑epub文件。
- 不支持字体嵌入或最不常用的epub 特征。
- 无内容验证-使用损坏或不受支持的HTML代码作为页面 内容将导致mkepub成功创建一个.epub文件 不符合EPUB3规范。
- 可能还有其他问题。
基本用法
importmkepubbook=mkepub.Book(title='An Example')book.add_page(title='First Page',content='Lorem Ipsum etcetera.')book.save('example.epub')
高级使用
importmkepubbook=mkepub.Book(title='Advanced Example',author='The Author')# multiple authors can be specified as a list:# mkepub.Book(title='Advanced Example', authors=['The First Author', 'The Second Author'])withopen('cover.jpg','rb')asfile:book.set_cover(file.read())withopen('style.css')asfile:book.set_stylesheet(file.read())first=book.add_page('Chapter 1','And so the book begins.')child=book.add_page('Chapter 1.1','Nested TOC is supported.',parent=first)book.add_page('Chapter 1.1.1','Infinite nesting levels',parent=child)book.add_page('Chapter 1.2','In any order you wish.',parent=first)book.add_page('Chapter 2','Use <b>html</b> to make your text <span class="pink">prettier</span>')book.add_page('Chapter 3: Images','<img src="images/chapter3.png" alt="You can use images as well">')# as long as you add them to the book:withopen('chapter3.png','rb')asfile:book.add_image('chapter3.png',file.read())book.save('advanced.epub')