Skip to content

Commit

Permalink
Fixed xpath error and catching error on non-numeric note ids
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrigg authored and acabal committed Jun 10, 2021
1 parent d0bb94b commit 055bcc1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions se/se_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,18 @@ def endnotes(self) -> list:
for node in dom.xpath("/html/body/section[contains(@epub:type, 'endnotes')]/ol/li[contains(@epub:type, 'endnote')]"):
note = Endnote()
note.node = node
# note that we DON'T need the existing note number, just the anchor as an ID for later matching
try:
note.number = int(node.get_attr("id").replace("note-", ""))
except ValueError:
note.number = 0
note.contents = node.xpath("./*")
note.anchor = node.get_attr("id") or ""

for back_link in node.xpath("//a[contains(@epub:type, 'backlink')]/@href"):
for back_link in node.xpath(".//a[contains(@epub:type, 'backlink')]/@href"):
note.back_link = back_link

if not note.back_link:
raise se.InvalidInputException(f"No backlink found in note {note.anchor} in existing endnotes file.")
self._endnotes.append(note)

return self._endnotes

@property
Expand Down

0 comments on commit 055bcc1

Please sign in to comment.