Commit 69138eaa authored by Abhilash Raj's avatar Abhilash Raj
Browse files

Merge branch 'fix-blockquote-rendering-in-md' into 'master'

fix: Render emails with patches as plaintext

Closes #494

See merge request !596
parents cd262ebe 935f281d
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@ News / Changelog
- Fixes the rendering of patches in markdown rendering mode.  (Fixes #393)
- Replace use of ``pytz`` with ``zoneinfo``.  (See !462)
- An attachment with content ``None`` is properly handled.  (Closes #496)
- Fix a bug which caused error in plaintext renderer when the
  email was quoted more than default no of. max_nested_levels
  in mistune. (Fixes #494)

.. _news-1.3.8:

+2 −2
Original line number Diff line number Diff line
@@ -185,8 +185,8 @@ def plugin_disable_markdown(md):
    markdown rendering.
    """
    md.block.rules = ['block_quote']
    md.block.block_quote_rules = ['block_quote']
    md.block.list_rules = ['block_quote']
    md.block.block_quote_rules = ['block_quote', 'blank_line']
    md.block.list_rules = []
    md.inline.rules = ['inline_html', 'auto_link']


+11 −3
Original line number Diff line number Diff line
from contextlib import suppress

from django import template
from django.utils.safestring import mark_safe

@@ -25,12 +27,18 @@ def render(email, mlist):
    """
    try:
        content = email.content
        display_fixed = email.display_fixed
    except AttributeError:
        content = email.get('content', '')
        display_fixed = email.get('display_fixed', False)

    if (
        mlist.archive_rendering_mode == ArchiveRenderingMode.markdown.name and
        not email.display_fixed
        not display_fixed
    ):
        with suppress(TypeError):
            return mark_safe(markdown_renderer(content))
    try:
        return mark_safe(text_renderer(content))
    except (KeyError, ValueError):
        return mark_safe('<pre>' + content + '</pre>')
+12 −0
Original line number Diff line number Diff line
@@ -296,6 +296,13 @@ class TestDecoratePlain(TestCase):
        result = text_renderer(contents)
        self.assertEqual(result.strip(), EXPECTED_TEST_EMAIL_PATCH_QUOTED)

    def test_plaintext_patch_gl_494(self):
        self.maxDiff = None
        contents = TEST_EMAIL_ISSUE_GL_494
        result = text_renderer(contents)
        self.assertEqual(
            result.strip(), TEST_EMAIL_TEXT_RENDER_RESULT.strip())


class SettingsValuesTest(TestCase):

@@ -387,3 +394,8 @@ ion_req;
function to return void?</p>
<div class="quoted-switch"><a href="#">...</a></div><blockquote class="blockquote quoted-text"><p>}</p>
</blockquote><p>Best</p>"""  # noqa: E501

TEST_EMAIL_ISSUE_GL_494 = """>> >>> >In the example"""

TEST_EMAIL_TEXT_RENDER_RESULT = """<div class="quoted-switch"><a href="#">...</a></div><blockquote class="blockquote quoted-text"><div class="quoted-switch"><a href="#">...</a></div><blockquote class="blockquote quoted-text"><div class="quoted-switch"><a href="#">...</a></div><blockquote class="blockquote quoted-text"><div class="quoted-switch"><a href="#">...</a></div><blockquote class="blockquote quoted-text"><div class="quoted-switch"><a href="#">...</a></div><blockquote class="blockquote quoted-text"><div class="quoted-switch"><a href="#">...</a></div><blockquote class="blockquote quoted-text"><p>In the example</p>
</blockquote></blockquote></blockquote></blockquote></blockquote></blockquote>"""  # noqa: E501