1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# encoding: utf-8 |
3
|
|
|
|
4
|
|
|
import mistune |
5
|
|
|
import unittest |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class mytest(unittest.TestCase): |
9
|
|
|
|
10
|
|
|
def testRender(self): |
11
|
|
|
self.assertEqual(False, False, 'Unit Test Start') |
12
|
|
|
|
13
|
|
|
def test_escape(self): |
14
|
|
|
ret = mistune.markdown('<div>**foo**</div>', escape=True) |
15
|
|
|
self.assertIn('>', ret, 'success') |
16
|
|
|
|
17
|
|
|
ret = mistune.markdown('this **foo** is <b>bold</b>', escape=True) |
18
|
|
|
self.assertIn('>', ret, 'success') |
19
|
|
|
|
20
|
|
|
def test_linebreak(self): |
21
|
|
|
ret = mistune.markdown('this **foo** \nis me') |
22
|
|
|
self.assertIsNot('<br>', ret, 'success') |
23
|
|
|
|
24
|
|
|
ret = mistune.markdown('this **foo** \nis me', hard_wrap=True) |
25
|
|
|
self.assertIn('<br>', ret, 'success') |
26
|
|
|
|
27
|
|
|
def test_skip_style(self): |
28
|
|
|
ret = mistune.markdown( |
29
|
|
|
'foo\n<style>body{color:red}</style>', skip_style=True |
30
|
|
|
) |
31
|
|
|
self.assertEqual(ret, '<p>foo</p>\n', 'success') |
32
|
|
|
|
33
|
|
|
def test_use_xhtml(self): |
34
|
|
|
ret = mistune.markdown('foo\n\n----\n\nbar') |
35
|
|
|
self.assertIn('<hr>', ret, 'success') |
36
|
|
|
ret = mistune.markdown('foo\n\n----\n\nbar', use_xhtml=True) |
37
|
|
|
self.assertIn('<hr />', ret, 'success') |
38
|
|
|
|
39
|
|
|
ret = mistune.markdown('foo \nbar', use_xhtml=True) |
40
|
|
|
self.assertIn('<br />', ret, 'success') |
41
|
|
|
|
42
|
|
|
ret = mistune.markdown('', use_xhtml=True) |
43
|
|
|
self.assertIn('<img src="bar" alt="foo" title="title" />', ret, 'success') |
44
|
|
|
|
45
|
|
|
def test_parse_inline_html(self): |
46
|
|
|
ret = mistune.markdown( |
47
|
|
|
'<div>**foo**</div>', parse_inline_html=True, escape=False |
48
|
|
|
) |
49
|
|
|
self.assertIsNot('<strong>', ret, 'success') |
50
|
|
|
ret = mistune.markdown( |
51
|
|
|
'<span>**foo**</span>', parse_inline_html=True, escape=False |
52
|
|
|
) |
53
|
|
|
self.assertIn('<span><strong>', ret, 'success') |
54
|
|
|
|
55
|
|
|
ret = mistune.markdown( |
56
|
|
|
'<a>http://lepture.com</a>', parse_inline_html=True, escape=False |
57
|
|
|
) |
58
|
|
|
self.assertIsNot('href', ret, 'sucess') |
59
|
|
|
|
60
|
|
|
def test_parse_block_html(self): |
61
|
|
|
ret = mistune.markdown( |
62
|
|
|
'<div>**foo**</div>', parse_block_html=True, escape=False |
63
|
|
|
) |
64
|
|
|
self.assertIn('<div><strong>', ret, 'success') |
65
|
|
|
ret = mistune.markdown( |
66
|
|
|
'<span>**foo**</span>', parse_block_html=True, escape=False |
67
|
|
|
) |
68
|
|
|
self.assertIsNot('<strong>', ret, 'success') |
69
|
|
|
|
70
|
|
|
def test_trigger_more_cases(self): |
71
|
|
|
markdown = mistune.Markdown( |
72
|
|
|
inline=mistune.InlineLexer, |
73
|
|
|
block=mistune.BlockLexer, |
74
|
|
|
skip_html=True |
75
|
|
|
) |
76
|
|
|
ret = markdown.render('foo[^foo]\n\n[^foo]: foo\n\n[^foo]: bar\n') |
77
|
|
|
self.assertEqual(ret.find('bar'), -1, 'success') |
78
|
|
|
|
79
|
|
|
def test_not_escape_block_tags(self): |
80
|
|
|
text = '<h1>heading</h1> text' |
81
|
|
|
self.assertIn(text, mistune.markdown(text, escape=False), 'success') |
82
|
|
|
|
83
|
|
|
def test_not_escape_inline_tags(self): |
84
|
|
|
text = '<a name="top"></a>' |
85
|
|
|
self.assertIn(text, mistune.markdown(text, escape=False), 'success') |
86
|
|
|
|
87
|
|
|
def test_hard_wrap_renderer(self): |
88
|
|
|
text = 'foo\nnewline' |
89
|
|
|
renderer = mistune.Renderer(hard_wrap=True) |
90
|
|
|
func = mistune.Markdown(renderer=renderer) |
91
|
|
|
self.assertIsNot('<br>', func(text), 'success') |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
if __name__ == '__main__': |
95
|
|
|
unittest.main() |
96
|
|
|
|