Subkapitel nicht in eBooklib in Python gezeigtPython

Python-Programme
Anonymous
 Subkapitel nicht in eBooklib in Python gezeigt

Post by Anonymous »

Objective
To programmatically create a epub file from text files
Problem
Some of the sub chapters are not shown
Minimal Reproducible Example
from ebooklib import epub

# Create a new EPUB book
book = epub.EpubBook()

# Set metadata
book.set_identifier('id123456')
book.set_title('book1')
book.set_language('en')
book.add_author('John Doe')

# Create a single chapter that includes all content
combined_chapter1 = epub.EpubHtml(title='Chaptor1', file_name='chapters1.xhtml', lang='en')

# Add content with main chapters, sub-chapters, and sub-sub-chapters
combined_chapter1.content = '''
Chapter 1: Main Topic
Introduction to Chapter 1.

1.1 Sub-Chapter
Content of sub-chapter 1.1.

1.1.1 Sub-Sub-Chapter
Detailed content of sub-sub-chapter 1.1.1.

1.2 Sub-Chapter
Content of sub-chapter 1.2.

1.2.1 Sub-Sub-Chapter
Detailed content of sub-sub-chapter 1.2.1.
'''

# Add the combined chapter to the book
book.add_item(combined_chapter1)

# Define Table of Contents with links to all sections
book.toc = (
epub.Link('chapters1.xhtml#chapter1', 'Chapter 1: Main Topic', 'chapter1'),
(
epub.Link('chapters1.xhtml#chapter1.1', '1.1 Sub-Chapter', 'chapter1.1'),
(
(epub.Link('chapters1.xhtml#chapter1.1.1', '1.1.1 Sub-Sub-Chapter', 'chapter1.1.1'),)
),
epub.Link('chapters1.xhtml#chapter1.2', '1.2 Sub-Chapter', 'chapter1.2'),
(
(epub.Link('chapters1.xhtml#chapter1.2.1', '1.2.1 Sub-Sub-Chapter', 'chapter1.2.1'),)
),
),
)

# Add navigation files
book.add_item(epub.EpubNcx())
nav = epub.EpubNav()
book.add_item(nav)

# Set the spine
book.spine = ['nav', combined_chapter1]

# Write the EPUB file
epub.write_epub('my_book_ch1_ch2.epub', book, {})
< /code>
Wie das Ergebnis aussieht < /H2>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post