From 818fd6c533b835b5ecea875ce3c27ca52f8fe00e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 5 May 2019 14:12:45 +0200 Subject: [PATCH] m.htmlsanity: make it possible to compact field lists again. 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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/m/htmlsanity.py b/plugins/m/htmlsanity.py index dacacd2d..dccdf868 100644 --- a/plugins/m/htmlsanity.py +++ b/plugins/m/htmlsanity.py @@ -514,10 +514,8 @@ class SaneHtmlTranslator(HTMLTranslator): Determine if the

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 + #

, 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) -- 2.30.2