简体   繁体   English

如何使用 ebooklib python 创建指向章节药水的链接

[英]how to create a link which points to the a potion of a chapter by using ebooklib python

I developing an application in DJango python to create EPub fies dynamically.我在 DJango python 中开发了一个应用程序来动态创建 EPub fies。 I am using CKEditor and ebooklib.我正在使用 CKEditor 和 ebooklib。 But I have a doubt with TOC, My intention is to create a link in TOC which points to the a potion of a chapter.但我对 TOC 有疑问,我的目的是在 TOC 中创建一个链接,指向一章的药水。 We can create the same as section and link to chapter but when i create so section load as a separate page,see its sample code below我们可以创建与部分相同的部分并链接到章节,但是当我创建这样的部分时,将其作为单独的页面加载,请参阅下面的示例代码

Please see the sample code请看示例代码

 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))
                )

But when I execute I will get section in a separate page.My intention is to point to the section of the chapter, not as a separate page.但是当我执行时,我会在单独的页面中获得部分。我的意图是指向章节的部分,而不是作为单独的页面。 (its like pointing to a subheading in chapter) and add section link in TOC (table of contents). (就像指向章节中的副标题一样)并在 TOC(目录)中添加章节链接。 Please help ?请帮忙 ?

Thanks谢谢

I don't know if you solved your problem or not, but I had the same issue and after a little testing and trying this and that I found a solution.我不知道你是否解决了你的问题,但我遇到了同样的问题,经过一些测试和尝试,我找到了解决方案。

The SOLUTION is to add the chapters you want as a epub.Link object.解决方案是将您想要的章节添加为epub.Link对象。 As an example:举个例子:

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

And add that result to a toc list object.并将该结果添加到目录列表对象。

toc.append(link)

Then after you have added all the chapters / links you want, then you convert the list to a tuple.然后在添加了所需的所有章节/链接后,将列表转换为元组。

toc = tuple(toc)

And set it as the book table of contents.并将其设置为书籍目录。

book.toc = toc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM