From: Vladimír Vondruš Date: Sun, 5 May 2019 12:12:45 +0000 (+0200) Subject: m.htmlsanity: make it possible to compact field lists again. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=818fd6c533b835b5ecea875ce3c27ca52f8fe00e;p=blog.git 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. --- 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)