chiark / gitweb /
m.htmlsanity: better consistency for collapsed <p>s in additional fields.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 2 Nov 2017 17:51:47 +0000 (18:51 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 2 Nov 2017 17:51:47 +0000 (18:51 +0100)
Previously (and that's also how stock Pelican behaves) article summaries
and other FORMATTED_FIELDS had <p> collapsing disabled completely. That
made some inconsistencies in the HTML markup (i.e., a m.css note in
article summary would look slightly differently compared to a note in
article content because of the additional <p>).

Now <p>s are collapsed for FORMATTED_FIELDS as well and the HTML writer
has an additional exception that it *does not* remove <p>s from nodes
that are directly inside field bodies.

pelican-plugins/m/htmlsanity.py

index 24dc5fb605b6284051a02c114cea9173fc776b1c..65d920d5bb542d27ed61dd82de844defd9b84631 100644 (file)
@@ -409,8 +409,10 @@ class SaneHtmlTranslator(HTMLTranslator):
         Determine if the <p> tags around paragraph ``node`` can be omitted.
         """
         if (isinstance(node.parent, nodes.document) or
-            isinstance(node.parent, nodes.compound)):
-            # Never compact paragraphs in document or compound.
+            isinstance(node.parent, nodes.compound) or
+            isinstance(node.parent, nodes.field_body)):
+            # Never compact paragraphs in document, compound or directly in
+            # field bodies (such as article summary or page footer)
             return False
         for key, value in node.attlist():
             if (node.is_not_default(key) and
@@ -504,7 +506,6 @@ class _SaneFieldBodyTranslator(SaneHtmlTranslator):
 
     def __init__(self, document):
         SaneHtmlTranslator.__init__(self, document)
-        self.compact_p = None
 
     def astext(self):
         return ''.join(self.body)