@@ -224,6 +224,26 @@ class Document:
|
||||
"""
|
||||
self.set_metadata(MetadataType.TITLE, title)
|
||||
|
||||
@property
|
||||
def title(self) -> Optional[str]:
|
||||
"""
|
||||
Get the document title as a property.
|
||||
|
||||
Returns:
|
||||
The document title, or None if not set
|
||||
"""
|
||||
return self.get_title()
|
||||
|
||||
@title.setter
|
||||
def title(self, title: str):
|
||||
"""
|
||||
Set the document title as a property.
|
||||
|
||||
Args:
|
||||
title: The document title
|
||||
"""
|
||||
self.set_title(title)
|
||||
|
||||
def find_blocks_by_type(self, block_type: BlockType) -> List[Block]:
|
||||
"""
|
||||
Find all blocks of a specific type.
|
||||
|
||||
@@ -14,7 +14,7 @@ import re
|
||||
import urllib.parse
|
||||
|
||||
from pyWebLayout.abstract.document import Document, Book, Chapter, MetadataType
|
||||
from pyWebLayout.io.readers.html import parse_html_string as parse_html, read_html_file as html_to_document
|
||||
from pyWebLayout.io.readers.html_extraction import parse_html_string
|
||||
|
||||
|
||||
# XML namespaces used in EPUB files
|
||||
@@ -346,6 +346,7 @@ class EPUBReader:
|
||||
add_to_toc_map(self.toc)
|
||||
|
||||
# Process spine items
|
||||
chapter_index = 0 # Keep track of actual content chapters
|
||||
for i, idref in enumerate(self.spine):
|
||||
if idref not in self.manifest:
|
||||
continue
|
||||
@@ -354,13 +355,20 @@ class EPUBReader:
|
||||
path = item['path']
|
||||
href = item['href']
|
||||
|
||||
# Skip navigation files
|
||||
if (idref == 'nav' or
|
||||
item.get('media_type') == 'application/xhtml+xml' and
|
||||
('nav' in href.lower() or 'toc' in href.lower())):
|
||||
continue
|
||||
|
||||
# Check if this item is in the TOC
|
||||
chapter_title = None
|
||||
if href in toc_map:
|
||||
chapter_title = toc_map[href]['label']
|
||||
|
||||
# Create a chapter
|
||||
chapter = self.book.create_chapter(chapter_title, i + 1)
|
||||
chapter_index += 1
|
||||
chapter = self.book.create_chapter(chapter_title, chapter_index)
|
||||
|
||||
# Parse the HTML content
|
||||
try:
|
||||
@@ -369,11 +377,10 @@ class EPUBReader:
|
||||
html = f.read()
|
||||
|
||||
# Parse HTML and add blocks to chapter
|
||||
base_url = os.path.dirname(path)
|
||||
document = parse_html(html, base_url=base_url)
|
||||
blocks = parse_html_string(html)
|
||||
|
||||
# Copy blocks to the chapter
|
||||
for block in document.blocks:
|
||||
for block in blocks:
|
||||
chapter.add_block(block)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -73,7 +73,7 @@ class Font:
|
||||
if self._font_size != 12: # Default size might not be 12
|
||||
self._font = ImageFont.truetype(self._font.path, self._font_size)
|
||||
except Exception as e:
|
||||
print(f"Error loading font: {e}")
|
||||
# Silently fall back to default font
|
||||
self._font = ImageFont.load_default()
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user