chiark / gitweb /
m.htmlsanity: make it possible to compact field lists again.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 5 May 2019 12:12:45 +0000 (14:12 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 21 May 2019 12:41:29 +0000 (14:41 +0200)
Do the patching in _SaneFieldBodyTranslator instead, but since both
Pelican theme (which wants field lists uncompacted) and Python docs
(which doesn't) use it, it has to allow another override again.

plugins/m/htmlsanity.py

index dacacd2d045f21d92ccbcdeaf80cb85174c98495..dccdf86898cc594b2006593e5f37b0f5eae9b9ef 100644 (file)
@@ -514,10 +514,8 @@ 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) 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)
+            isinstance(node.parent, nodes.compound)):
+            # Never compact paragraphs in document or compound
             return False
         for key, value in node.attlist():
             if (node.is_not_default(key) and
@@ -648,6 +646,16 @@ class _SaneFieldBodyTranslator(SaneHtmlTranslator):
     def __init__(self, document):
         SaneHtmlTranslator.__init__(self, document)
 
+    # Overriding the function in SaneHtmlTranslator, in addition never
+    # compacting paragraphs directly in field bodies (such as article summary
+    # or page footer) unless explicitly told it so. The sad thing is that the
+    # Pelican theme currently always expects the summaries to be wrapped in
+    # <p>, while the Python docs expect exactly the other case.
+    def should_be_compact_paragraph(self, node):
+        if isinstance(node.parent, nodes.field_body) and not self.compact_field_list:
+            return False
+        return SaneHtmlTranslator.should_be_compact_paragraph(self, node)
+
     def astext(self):
         return ''.join(self.body)