From 0efc23da18690c2bf0faba792920a96afdf4b928 Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Tue, 24 May 2022 21:11:30 +0200 Subject: [PATCH] =?UTF-8?q?Corrige=20le=20contenu=20des=20ePUBs=20pour=20i?= =?UTF-8?q?nterpr=C3=A9ter=20l'HTML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #6313 --- zds/utils/templatetags/emarkdown.py | 2 +- zds/utils/tests/tests_emarkdown.py | 31 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/zds/utils/templatetags/emarkdown.py b/zds/utils/templatetags/emarkdown.py index 0556f8ae86..f2bd45299c 100644 --- a/zds/utils/templatetags/emarkdown.py +++ b/zds/utils/templatetags/emarkdown.py @@ -153,7 +153,7 @@ def epub_markdown(md_input, image_directory): replaced_media_url = settings.MEDIA_URL if replaced_media_url.startswith("/"): replaced_media_url = replaced_media_url[1:] - return ( + return mark_safe( emarkdown( md_input, output_format="epub", diff --git a/zds/utils/tests/tests_emarkdown.py b/zds/utils/tests/tests_emarkdown.py index 85413e0326..7b168e1fb2 100644 --- a/zds/utils/tests/tests_emarkdown.py +++ b/zds/utils/tests/tests_emarkdown.py @@ -1,3 +1,4 @@ +from collections import namedtuple from textwrap import dedent from django.test import TestCase @@ -8,15 +9,9 @@ class EMarkdownTest(TestCase): def setUp(self): - content = "# Titre 1\n\n## Titre **2**\n\n### Titre 3\n\n> test" - self.context = Context({"content": content}) - - def test_emarkdown(self): - # The goal is not to test zmarkdown but test that template tag correctly call it - - tr = Template("{% load emarkdown %}{{ content | emarkdown}}").render(self.context) - - expected = ( + self.content = "# Titre 1\n\n## Titre **2**\n\n### Titre 3\n\n> test" + self.context = Context({"content": self.content}) + self.long_expected = ( '

Titre 1

\n

' 'Titre 2

\n
\n

test

\n
" ) - self.assertEqual(tr, expected) + + def test_emarkdown(self): + # The goal is not to test zmarkdown but test that template tag correctly call it + + tr = Template("{% load emarkdown %}{{ content | emarkdown}}").render(self.context) + + self.assertEqual(tr, self.long_expected) # Todo: Find a way to force parsing crash or simulate it. + def test_epub_markdown(self): + DirTuple = namedtuple("DirTuple", ["absolute", "relative"]) + image_directory = DirTuple("/some/absolute/path", "../some/relative/path") + + tr = Template("{% load emarkdown %}{{ content | epub_markdown:image_directory }}").render( + Context({"content": self.content, "image_directory": image_directory}) + ) + + self.assertEqual(tr, self.long_expected) + def test_emarkdown_inline(self): # The goal is not to test zmarkdown but test that template tag correctly call it