Skip to content

Commit

Permalink
Merge pull request #25 from nikolas/html-code-tests
Browse files Browse the repository at this point in the history
Add tests to make sure code blocks get rendered correctly

Thanks Nik Nyby @nikolas
  • Loading branch information
Alir3z4 committed Sep 10, 2015
2 parents cb56614 + c03072d commit fc25de0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.rst
@@ -1,3 +1,11 @@
1.5
==============
----

* Added tests for rendering code blocks.



1.4 2015-04-26
==============
----
Expand Down
72 changes: 72 additions & 0 deletions django_markwhat/tests.py
Expand Up @@ -37,6 +37,27 @@ class Templates(unittest.TestCase):
## An h2"""

markdown_content_with_html_code = """Paragraph 1
## An h2
```
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
</video>
```
"""

markdown_content_with_iframe_code = """Paragraph 1
## An h2
```
<iframe src="http://example.com"></iframe>
```
"""

rest_content = """Paragraph 1
Paragraph 2 with a link_
Expand Down Expand Up @@ -66,6 +87,31 @@ def test_markdown(self):
pattern = re.compile("""<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>""")
self.assertTrue(pattern.match(rendered))

@unittest.skipUnless(markdown, 'markdown not installed')
def test_markdown_html_code(self):
t = Template("{% load markup %}{{ markdown_content|markdown }}")
rendered = t.render(Context({
'markdown_content': self.markdown_content_with_html_code
})).strip()
pattern = re.compile(
'<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>' +
'\s*<p><code>\s*&lt;video width="320"'
)
self.assertTrue(pattern.match(rendered))

@unittest.skipUnless(markdown, 'markdown not installed')
def test_markdown_html_iframe_code(self):
t = Template("{% load markup %}{{ markdown_content|markdown }}")
rendered = t.render(Context({
'markdown_content': self.markdown_content_with_iframe_code
})).strip()
pattern = re.compile(
'<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>' +
'\s*<p><code>\s*&lt;iframe src="http://example.com"&gt;' +
'&lt;/iframe&gt;'
)
self.assertTrue(pattern.match(rendered))

@unittest.skipUnless(
markdown and markdown_version >= (2, 1),
'markdown >= 2.1 not installed'
Expand Down Expand Up @@ -103,6 +149,32 @@ def test_commonmark(self):
pattern = re.compile("""<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>""")
self.assertTrue(pattern.match(rendered))

@unittest.skipUnless(CommonMark, 'commonmark not installed')
def test_commonmark_html_code(self):
t = Template("{% load markup %}{{ markdown_content|commonmark }}")
rendered = t.render(Context({
'markdown_content': self.markdown_content_with_html_code
})).strip()
pattern = re.compile(
'<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>' +
'\s*<pre><code>\s*&lt;video width=&quot;320&quot'
)
self.assertTrue(pattern.match(rendered))

@unittest.skipUnless(CommonMark, 'commonmark not installed')
def test_commonmark_html_iframe_code(self):
t = Template("{% load markup %}{{ markdown_content|commonmark }}")
rendered = t.render(Context({
'markdown_content': self.markdown_content_with_iframe_code
})).strip()
pattern = re.compile(
'<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>' +
'\s*<pre><code>\s*&lt;iframe ' +
'src=&quot;http://example.com&quot;&gt;' +
'&lt;/iframe&gt;'
)
self.assertTrue(pattern.match(rendered))

@unittest.skipUnless(CommonMark, 'commonmark not installed')
def test_commonmark_empty_str(self):
t = Template("{% load markup %}{{ markdown_content|commonmark }}")
Expand Down

0 comments on commit fc25de0

Please sign in to comment.