"""KEPUB 文件的 XML/XHTML 模板""" MIMETYPE = "application/epub+zip" CONTAINER_XML = """\ """ STYLE_CSS = """\ body { margin: 0; padding: 0; } svg { width: 100%; height: 100%; }""" def content_opf( *, uuid: str, title: str, author: str | None, language: str, description: str | None, series_name: str | None, series_index: float | None, modified: str, manifest_items: str, spine_items: str, viewport_w: int, viewport_h: int, ) -> str: """生成 content.opf 包文档。""" meta_extra = "" if description: # 转义 XML 特殊字符 desc_escaped = ( description.replace("&", "&") .replace("<", "<") .replace(">", ">") ) meta_extra += f"\n {desc_escaped}" if series_name: series_escaped = series_name.replace("&", "&").replace('"', """) meta_extra += f'\n ' if series_index is not None: meta_extra += ( f'\n ' ) author_tag = "" if author: author_escaped = author.replace("&", "&").replace("<", "<") author_tag = f"\n {author_escaped}" return f"""\ urn:uuid:{uuid} {title}{author_tag} {language} {modified} pre-paginated portrait none{meta_extra} {manifest_items} {spine_items} """ def toc_ncx(*, uuid: str, title: str, nav_points: str) -> str: """生成 toc.ncx 导航文件。""" title_escaped = title.replace("&", "&").replace("<", "<") return f"""\ {title_escaped} {nav_points} """ def nav_xhtml(*, title: str, nav_items: str) -> str: """生成 EPUB3 nav.xhtml 导航文档。""" title_escaped = title.replace("&", "&").replace("<", "<") return f"""\ {title_escaped} """ def page_xhtml( *, page_num: int, image_filename: str, viewport_w: int, viewport_h: int ) -> str: """生成单页 XHTML(固定布局,SVG 包裹图片)。""" return f"""\ Page {page_num}
"""