fixes for edge cases
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 16 Jun 2023 08:01:18 +0000 (10:01 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 16 Jun 2023 08:01:18 +0000 (10:01 +0200)
src/librarian/builders/html.py
src/librarian/document.py
src/librarian/elements/base.py

index 18a5b36..7504a66 100644 (file)
@@ -51,7 +51,8 @@ class HtmlBuilder:
         return self.current_cursors[-1]
 
     def enter_fragment(self, fragment):
         return self.current_cursors[-1]
 
     def enter_fragment(self, fragment):
-        self.current_cursors.append(self.cursors[fragment])
+        cursor = self.cursors.get(fragment, self.cursor)
+        self.current_cursors.append(cursor)
 
     def exit_fragment(self):
         self.current_cursors.pop()
 
     def exit_fragment(self):
         self.current_cursors.pop()
index d4063c5..6cdf191 100644 (file)
@@ -101,7 +101,10 @@ class WLDocument:
         def _compat_assigns_section_ids_in_elem(elem, prefix='sec'):
             for i, child in enumerate(elem):
                 idfier = '{}{}'.format(prefix, i + 1)
         def _compat_assigns_section_ids_in_elem(elem, prefix='sec'):
             for i, child in enumerate(elem):
                 idfier = '{}{}'.format(prefix, i + 1)
-                child.attrib['_compat_section_id'] = idfier
+                try:
+                    child.attrib['_compat_section_id'] = idfier
+                except:
+                    pass
                 _compat_assigns_section_ids_in_elem(child, idfier + '-')
         _compat_assigns_section_ids_in_elem(self.tree.getroot().master)
 
                 _compat_assigns_section_ids_in_elem(child, idfier + '-')
         _compat_assigns_section_ids_in_elem(self.tree.getroot().master)
 
index 646067e..8e83311 100644 (file)
@@ -278,8 +278,6 @@ class WLElement(etree.ElementBase):
             # do we dare go up?
             parent = self.getparent()
             if parent is not None and parent.CAN_HAVE_TEXT:
             # do we dare go up?
             parent = self.getparent()
             if parent is not None and parent.CAN_HAVE_TEXT:
-                print(etree.tostring(self, encoding='unicode'))
-                assert False
                 words, parsnip = parent.snip(words, before=self)
                 return words, parsnip[:-1] + snippet + parsnip[-1:]
 
                 words, parsnip = parent.snip(words, before=self)
                 return words, parsnip[:-1] + snippet + parsnip[-1:]