Fixes for rare caces.
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 8 Jul 2021 14:10:47 +0000 (16:10 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 8 Jul 2021 14:10:47 +0000 (16:10 +0200)
src/librarian/document.py
src/librarian/elements/base.py
src/librarian/elements/figures/ilustr.py

index e220c14..a3ee093 100644 (file)
@@ -20,6 +20,8 @@ class WLDocument:
 
         self.provider = provider if provider is not None else DirDocProvider('.')
 
 
         self.provider = provider if provider is not None else DirDocProvider('.')
 
+        self.tree.getroot().validate()
+
     @property
     def meta(self):
         # Allow metadata of the master element as document meta.
     @property
     def meta(self):
         # Allow metadata of the master element as document meta.
@@ -81,9 +83,9 @@ class WLDocument:
     def editors(self):
         persons = set(self.meta.editors
                       + self.meta.technical_editors)
     def editors(self):
         persons = set(self.meta.editors
                       + self.meta.technical_editors)
-        #for child in self.parts():
-        #    persons.update(child.editors())
-        #if None in persons:
-        #    persons.remove(None)
+        for child in self.children:
+            persons.update(child.editors())
+        if None in persons:
+            persons.remove(None)
         return persons
 
         return persons
 
index 5317268..1d3edd6 100644 (file)
@@ -67,6 +67,8 @@ class WLElement(etree.ElementBase):
         t = ''
         t += self.normalize_text(self.text)
         for c in self:
         t = ''
         t += self.normalize_text(self.text)
         for c in self:
+            if not isinstance(c, WLElement):
+                continue
             if c.tag not in ('pe', 'pa', 'pt', 'pr', 'motyw'):
                 t += c.raw_printable_text()
             t += self.normalize_text(c.tail)
             if c.tag not in ('pe', 'pa', 'pt', 'pr', 'motyw'):
                 t += c.raw_printable_text()
             t += self.normalize_text(c.tail)
@@ -152,16 +154,20 @@ class WLElement(etree.ElementBase):
         return attr
 
     def epub_build(self, builder):
         return attr
 
     def epub_build(self, builder):
+        from librarian.elements.masters import Master
+
         # TEMPORARY
         self.CAN_HAVE_TEXT = True
         self.STRIP = False
         # TEMPORARY
         self.CAN_HAVE_TEXT = True
         self.STRIP = False
-        
-        if self.EPUB_START_CHUNK:
+       
+        start_chunk = self.EPUB_START_CHUNK and isinstance(self.getparent(), Master)
+
+        if start_chunk:
             builder.start_chunk()
 
         fragment = None
         if self.SECTION_PRECEDENCE:
             builder.start_chunk()
 
         fragment = None
         if self.SECTION_PRECEDENCE:
-            if not self.EPUB_START_CHUNK:
+            if not start_chunk:
                 fragment = 'sub%d' % builder.assign_section_number()
                 self.attrib['id'] = fragment
 
                 fragment = 'sub%d' % builder.assign_section_number()
                 self.attrib['id'] = fragment
 
@@ -183,7 +189,21 @@ class WLElement(etree.ElementBase):
         self._epub_build_inner(builder)
         if self.EPUB_TAG:
             builder.end_element()
         self._epub_build_inner(builder)
         if self.EPUB_TAG:
             builder.end_element()
-            
+
+    def validate(self):
+        from librarian.elements.masters import Master
+        from librarian.elements.blocks import DlugiCytat, PoezjaCyt
+
+        if self.SECTION_PRECEDENCE:
+            assert isinstance(self.getparent(), (Master, DlugiCytat, PoezjaCyt)), \
+                    'Header {} inside a <{}> instead of a master.'.format(
+                            etree.tostring(self), self.getparent().tag)
+
+        for c in self:
+            if isinstance(c, WLElement):
+                c.validate()
+
+
     def sanitize(self):
         # TODO: Remove insanity here.
         for e in self:
     def sanitize(self):
         # TODO: Remove insanity here.
         for e in self:
index c6105f4..af936fb 100644 (file)
@@ -43,8 +43,8 @@ class Ilustr(WLElement):
         
         return {
             'src': file_name,
         
         return {
             'src': file_name,
-            'alt': self.attrib['alt'],
-            'title': self.attrib['alt'],
+            'alt': self.attrib.get('alt', ''),
+            'title': self.attrib.get('alt', ''),
         }
 
     get_epub_attr = get_html_attr
         }
 
     get_epub_attr = get_html_attr