From bd97f61d25eb0c3e51a29286c7de509146eceb37 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 16 Jun 2023 10:01:18 +0200 Subject: [PATCH 1/1] fixes for edge cases --- src/librarian/builders/html.py | 3 ++- src/librarian/document.py | 5 ++++- src/librarian/elements/base.py | 2 -- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librarian/builders/html.py b/src/librarian/builders/html.py index 18a5b36..7504a66 100644 --- a/src/librarian/builders/html.py +++ b/src/librarian/builders/html.py @@ -51,7 +51,8 @@ class HtmlBuilder: 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() diff --git a/src/librarian/document.py b/src/librarian/document.py index d4063c5..6cdf191 100644 --- a/src/librarian/document.py +++ b/src/librarian/document.py @@ -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) - 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) diff --git a/src/librarian/elements/base.py b/src/librarian/elements/base.py index 646067e..8e83311 100644 --- a/src/librarian/elements/base.py +++ b/src/librarian/elements/base.py @@ -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: - print(etree.tostring(self, encoding='unicode')) - assert False words, parsnip = parent.snip(words, before=self) return words, parsnip[:-1] + snippet + parsnip[-1:] -- 2.20.1