Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige le contenu des ePUBs pour interpréter l'HTML #6318

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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