如何使用电子书库python创建指向章节药剂的链接

2024-04-25 06:01:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用DJango python开发一个应用程序来动态创建EPub。我正在使用CKEditor和ebooklib。但我对TOC有一个疑问,我的意图是在TOC中创建一个链接,指向一个章节的药剂。我们可以创建与section相同的内容并链接到chapter,但当我创建so section load作为单独页面时,请参见下面的示例代码

请参阅示例代码

 c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml')
    c2.content='<h1>About this book</h1><p>Helou, this is my book! There are many books, but this one is mine.</p>'
    c2.set_language('hr')
    c2.properties.append('rendition:layout-pre-paginated rendition:orientation-landscape rendition:spread-none')
    c2.add_item(default_css)

    # add chapters to the book
    book.add_item(c1)
    book.add_item(c2)

  
    # create table of contents
    # - add manual link
    # - add section
    # - add auto created links to chapters

    book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'),
                (epub.Section('Languages'),
                 (c1, c2))
                )

但是当我执行的时候,我会在一个单独的页面中得到一节,我的意图是指向章节的一节,而不是作为一个单独的页面。(就像指向第章中的子目)并在目录中添加章节链接。请帮忙

谢谢


Tags: add示例链接section页面epubthisitem
1条回答
网友
1楼 · 发布于 2024-04-25 06:01:15

我不知道你是否解决了你的问题,但我也有同样的问题,经过一点测试和尝试,我找到了一个解决方案

解决方案是将您想要的章节添加为epub.Link对象。例如:

epub.Link(chapter.file_name, chapter.title, chapter.id)

并将该结果添加到toc列表对象中

toc.append(link)

然后,在添加了所需的所有章节/链接后,将列表转换为元组

toc = tuple(toc)

并将其设置为图书目录

book.toc = toc

相关问题 更多 >