Skip to content

Commit

Permalink
Corrige le contenu des ePUBs pour interpréter l'HTML
Browse files Browse the repository at this point in the history
Fix #6313
  • Loading branch information
philippemilink committed May 24, 2022
1 parent 36fdfd3 commit d2f2883
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion zds/utils/templatetags/emarkdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 21 additions & 10 deletions zds/utils/tests/tests_emarkdown.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import namedtuple
from textwrap import dedent

from django.test import TestCase
Expand All @@ -8,26 +9,36 @@

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 = (
'<h3 id="titre-1">Titre 1<a aria-hidden="true" tabindex="-1" href="#titre-1">'
'<span class="icon icon-link"></span></a></h3>\n<h4 id="titre-2">'
'Titre <strong>2</strong><a aria-hidden="true" tabindex="-1" href="#titre-2"><span'
' class="icon icon-link"></span></a></h4>\n<h5 id="titre-3">Titre 3'
'<a aria-hidden="true" tabindex="-1" href="#titre-3"><span class="icon icon-link">'
"</span></a></h5>\n<blockquote>\n<p>test</p>\n</blockquote>"
)
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

Expand Down

0 comments on commit d2f2883

Please sign in to comment.