X-Git-Url: https://git.madduck.net/etc/neomutt.git/blobdiff_plain/9530928737e4bee2e022b77803de57d62181e101..c9607f9bea3104bc18373f8f44bab1215378d798:/.config/neomutt/buildmimetree.py diff --git a/.config/neomutt/buildmimetree.py b/.config/neomutt/buildmimetree.py index c541ed1..1ff0cb0 100755 --- a/.config/neomutt/buildmimetree.py +++ b/.config/neomutt/buildmimetree.py @@ -28,6 +28,9 @@ # - Pynliner, provides --css-file and thus inline styling of HTML output # - Pygments, then syntax highlighting for fenced code is enabled # +# Running tests: +# pytest -x buildmimetree.py +# # Latest version: # https://git.madduck.net/etc/neomutt.git/blob_plain/HEAD:/.config/neomutt/buildmimetree.py # @@ -47,6 +50,7 @@ import bs4 import xml.etree.ElementTree as etree import io import enum +from contextlib import contextmanager from collections import namedtuple, OrderedDict from markdown.extensions import Extension from markdown.blockprocessors import BlockProcessor @@ -482,8 +486,12 @@ class QuoteToAdmonitionExtension(Extension): def __init__(self, parser): super().__init__(parser) self._title = None + self._disable = False def test(self, parent, blocks): + if self._disable: + return False + if markdown.util.nearing_recursion_limit(): return False @@ -519,9 +527,16 @@ class QuoteToAdmonitionExtension(Extension): self.parser.parseChunk(admonition, self._title) admonition[0].set("class", "admonition-title") - self.parser.parseChunk( - admonition, "\n".join(self.clean(line) for line in quotelines) - ) + with self.disable(): + self.parser.parseChunk( + admonition, "\n".join(quotelines) + ) + + @contextmanager + def disable(self): + self._disable = True + yield True + self._disable = False @classmethod def clean(klass, line): @@ -2037,6 +2052,29 @@ try: p = quote.p.extract() assert p.contents[1].name == "strong" + @pytest.mark.converter + def test_converter_attribution_to_admonition_with_blockquote( + self, fakepath, fakefilefactory + ): + mailparts = ( + "Regarding whatever", + "> blockquote line1", + "> blockquote line2", + "> ", + "> new para with **bold** text", + ) + with fakefilefactory( + fakepath, content="\n".join(mailparts) + ) as draft_f: + convert_markdown_to_html(draft_f, filefactory=fakefilefactory) + + soup = bs4.BeautifulSoup( + fakefilefactory[fakepath.with_suffix(".html")].read(), + "html.parser", + ) + quote = soup.select_one("div.admonition.quote") + assert quote.blockquote + @pytest.mark.converter def test_converter_attribution_to_admonition_multiple( self, fakepath, fakefilefactory