Skip to content

Commit

Permalink
Simplify logic for finding parent/ancestor note element
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Oct 22, 2024
1 parent 5577ade commit b6ec86e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ppa/archive/eebo_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ def text_inside_note(self, text):
if not self.notes:
return None

within_note = None
# check if this text is directly inside a note tag
within_note = None
# check if this is normal text directly inside a note tag
parent = text.getparent()
if parent.tag == "NOTE" and not text.is_tail:
if parent.tag == "NOTE" and text.is_text:
within_note = parent
# otherwise, check if text is nested under a note tag
# otherwise, check if text is nested somewhere under a note tag
else:
for ancestor in parent.iterancestors():
if ancestor.tag == "NOTE":
within_note = ancestor
break
note_ancestors = parent.xpath("ancestor::NOTE[1]")
within_note = note_ancestors[0] if note_ancestors else None

return within_note

Expand Down

0 comments on commit b6ec86e

Please sign in to comment.