Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed spurious indenting problem for some cases #634

Merged
merged 2 commits into from
Dec 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions se/se_epub_generate_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,24 +413,27 @@ def process_headings(dom: EasyXmlTree, textf: str, toc_list: list, single_file:
# Find all the hgroups and h1, h2 etc headings.
heads = dom.xpath("//hgroup | //h1 | //h2 | //h3 | //h4 | //h5 | //h6")

# special treatment where we can't find any header or hgroups
# special treatment where we can't find any heading or hgroups
if not heads: # May be a dedication or an epigraph, with no heading tag.
special_item = TocItem()
# Need to determine level depth.
# We don't have a heading, so get first content item
content_item = dom.xpath("//p | //header | //img")
if content_item:
special_item.level = get_level(content_item[0], toc_list)
if content_item: # check to see if it has a data-parent, if so, we'll use that to determine depth
data_parent = content_item[0].xpath("//*[@data-parent]")
if data_parent:
special_item.level = get_level(content_item[0], toc_list)
else: # special items without data-parents get a default dept of 1
special_item.level = 1
else:
raise se.InvalidInputException(f"Unable to find heading or content item (p, header or img) in file: [path][link=file://{textf}]{textf}[/][/].")
special_item.title = dom.xpath("//head/title/text()", True) # Use the page title as the ToC entry title.
if special_item.title is None:
special_item.title = "NO TITLE"
special_item.file_link = textf
special_item.toc_id = get_toc_id_for_special_item(content_item[0])
if not special_item.toc_id: # no id found, report as error
raise se.InvalidInputException("Couldn’t determine section or article id in file: [path][link=file://{textf}]{textf}[/][/].")
special_item.toc_id = textf.replace('.xhtml','') # quick and dirty way of getting the id of a special item
if not special_item.toc_id: # no luck so use quick and dirty method
special_item.toc_id = textf.replace('.xhtml','')
special_item.place = place
toc_list.append(special_item)
return
Expand Down