Skip to content

Commit

Permalink
made rst2folia more robust for failures #17
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Nov 10, 2020
1 parent 696de0e commit ba82e92
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions foliatools/rst2folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def initstructure(self, tag, **attribs):
id = self.generate_id(parentid, tag)
parentclass = folia.XML2CLASS[parenttag]
currentclass = folia.XML2CLASS[tag]
if not parentclass.accepts(currentclass):
try:
parentclass.accepts(currentclass)
except ValueError:
print("WARNING: Adding " + tag + " to " + parenttag + " would violate FoLiA constraints. Skipping this element!",file=sys.stderr)
self.path.append( (None, None) )
return
Expand All @@ -231,7 +233,7 @@ def initstructure(self, tag, **attribs):
def closestructure(self, tag):
"""Generic depart function for structure elements"""
_tag, id = self.path.pop()
if tag is None: #we skip this one (nesting violates folia constraints)
if tag is None or _tag is None: #we skip this one (nesting violates folia constraints)
return
elif not tag == _tag:
raise Exception("Mismatch in closestructure, expected closure for " + tag + ", got " + _tag)
Expand Down

0 comments on commit ba82e92

Please sign in to comment.