1
|
|
|
# -*- coding: utf-8 -*-
|
2
|
|
|
import unittest
|
3
|
|
|
from tcms.core.templatetags.extra_filters import markdown2html
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class TestMarkdownExtraFilters(unittest.TestCase):
|
7
|
|
|
|
8
|
|
|
def test_markdown2html_convert_paragraphs(self):
|
9
|
|
|
self.assertEqual(markdown2html("__*hello!*__"),
|
10
|
|
|
"<p><strong><em>hello!</em></strong></p>")
|
11
|
|
|
|
12
|
|
|
def test_markdown2html_convert_tables(self):
|
13
|
|
|
self.assertEqual(markdown2html("""|Stx |Desc |\n|----|-----|\n|Head|Title|\n|Txt|Txt |"""),
|
14
|
|
|
"""<table>
|
15
|
|
|
<thead>
|
16
|
|
|
<tr>
|
17
|
|
|
<th>Stx</th>
|
18
|
|
|
<th>Desc</th>
|
19
|
|
|
</tr>
|
20
|
|
|
</thead>
|
21
|
|
|
<tbody>
|
22
|
|
|
<tr>
|
23
|
|
|
<td>Head</td>
|
24
|
|
|
<td>Title</td>
|
25
|
|
|
</tr>
|
26
|
|
|
<tr>
|
27
|
|
|
<td>Txt</td>
|
28
|
|
|
<td>Txt</td>
|
29
|
|
|
</tr>
|
30
|
|
|
</tbody>
|
31
|
|
|
</table>""")
|
32
|
|
|
|
33
|
|
|
def test_markdown2html_convert_nl2br(self):
|
34
|
|
|
self.assertEqual(markdown2html("""Line 1
|
35
|
|
|
Line 2"""), """<p>Line 1<br>
|
36
|
|
|
Line 2</p>""")
|
37
|
|
|
|
38
|
|
|
def test_markdown2html_convert_fenced_code(self):
|
39
|
|
|
self.assertEqual(markdown2html("""```{
|
40
|
|
|
"firstName": "John",
|
41
|
|
|
"lastName": "Smith",
|
42
|
|
|
"age": 25}``` """), """<p><code>{
|
43
|
|
|
"firstName": "John",
|
44
|
|
|
"lastName": "Smith",
|
45
|
|
|
"age": 25}</code> </p>""")
|
46
|
|
|
|
47
|
|
|
def test_markdown2html_does_bleach_unsafe_code(self):
|
48
|
|
|
self.assertEqual(markdown2html("### hello <script>alert('gotcha');</script>"),
|
49
|
|
|
"<h3>hello <script>alert('gotcha');</script></h3>")
|
50
|
|
|
|
51
|
|
|
self.assertEqual(markdown2html("<canvas><bgsound><audio><applet>"),
|
52
|
|
|
"<canvas><bgsound><audio><applet>")
|
53
|
|
|
|
54
|
|
|
self.assertEqual(markdown2html("""_hello_ <html><head></head>
|
55
|
|
|
<body></body></html>"""), """<p><em>hello</em> <html><head></head><br>
|
56
|
|
|
<body></body></html></p>""")
|
57
|
|
|
|
58
|
|
|
self.assertEqual(markdown2html("""__hello__ <xmp><video><track>
|
59
|
|
|
<title><rt><ruby><param>"""), """<p><strong>hello</strong> <xmp><video><track><br>
|
60
|
|
|
<title><rt><ruby><param></p>""")
|
61
|
|
|
|
62
|
|
|
self.assertEqual(markdown2html("""*hello* <object><link><iframe>
|
63
|
|
|
<frame><frameset><embed>"""), """<p><em>hello</em> <object><link><iframe><br>
|
64
|
|
|
<frame><frameset><embed></p>""")
|
65
|
|
|
|