@@ -27,10 +27,170 @@ class TestSmarty(TestCase):
27
27
28
28
default_kwargs = {'extensions' : ['smarty' ]}
29
29
30
+ def test_basic (self ):
31
+ self .assertMarkdownRenders (
32
+ "It's fun. What's fun?" ,
33
+ '<p>It’s fun. What’s fun?</p>'
34
+ )
35
+ self .assertMarkdownRenders (
36
+ '"Isn\' t this fun"? --- she said...' ,
37
+ '<p>“Isn’t this fun”? — she said…</p>'
38
+ )
39
+ self .assertMarkdownRenders (
40
+ '"\' Quoted\' words in a larger quote."' ,
41
+ '<p>“‘Quoted’ words in a larger quote.”</p>'
42
+ )
43
+ self .assertMarkdownRenders (
44
+ '\' Quoted "words" in a larger quote.\' ' ,
45
+ '<p>‘Quoted “words” in a larger quote.’</p>'
46
+ )
47
+ self .assertMarkdownRenders (
48
+ '"quoted" text and **bold "quoted" text**' ,
49
+ '<p>“quoted” text and <strong>bold “quoted” text</strong></p>'
50
+ )
51
+ self .assertMarkdownRenders (
52
+ "'quoted' text and **bold 'quoted' text**" ,
53
+ '<p>‘quoted’ text and <strong>bold ‘quoted’ text</strong></p>'
54
+ )
55
+ self .assertMarkdownRenders (
56
+ 'em-dashes (---) and ellipes (...)' ,
57
+ '<p>em-dashes (—) and ellipes (…)</p>'
58
+ )
59
+ self .assertMarkdownRenders (
60
+ '"[Link](http://example.com)" --- she said.' ,
61
+ '<p>“<a href="http://example.com">Link</a>” — she said.</p>'
62
+ )
63
+ self .assertMarkdownRenders (
64
+ '"Ellipsis within quotes..."' ,
65
+ '<p>“Ellipsis within quotes…”</p>'
66
+ )
67
+
68
+ def test_years (self ):
69
+ self .assertMarkdownRenders ("1440--80's" , '<p>1440–80’s</p>' )
70
+ self .assertMarkdownRenders ("1440--'80s" , '<p>1440–’80s</p>' )
71
+ self .assertMarkdownRenders ("1440---'80s" , '<p>1440—’80s</p>' )
72
+ self .assertMarkdownRenders ("1960's" , '<p>1960’s</p>' )
73
+ self .assertMarkdownRenders ("one two '60s" , '<p>one two ’60s</p>' )
74
+ self .assertMarkdownRenders ("'60s" , '<p>’60s</p>' )
75
+
76
+ def test_wrapping_line (self ):
77
+ text = (
78
+ "A line that 'wraps' with\n "
79
+ "*emphasis* at the beginning of the next line."
80
+ )
81
+ html = (
82
+ '<p>A line that ‘wraps’ with\n '
83
+ '<em>emphasis</em> at the beginning of the next line.</p>'
84
+ )
85
+ self .assertMarkdownRenders (text , html )
86
+
87
+ def test_escaped (self ):
88
+ self .assertMarkdownRenders (
89
+ 'Escaped \\ -- ndash' ,
90
+ '<p>Escaped -- ndash</p>'
91
+ )
92
+ self .assertMarkdownRenders (
93
+ '\\ \' Escaped\\ \' \\ "quotes\\ "' ,
94
+ '<p>\' Escaped\' "quotes"</p>'
95
+ )
96
+ self .assertMarkdownRenders (
97
+ 'Escaped ellipsis\\ ...' ,
98
+ '<p>Escaped ellipsis...</p>'
99
+ )
100
+ self .assertMarkdownRenders (
101
+ '\' Escaped \\ "quotes\\ " in real ones\' ' ,
102
+ '<p>‘Escaped "quotes" in real ones’</p>'
103
+ )
104
+ self .assertMarkdownRenders (
105
+ '\\ \' "Real" quotes in escaped ones\\ \' ' ,
106
+ "<p>'“Real” quotes in escaped ones'</p>"
107
+ )
108
+
30
109
def test_escaped_attr (self ):
31
110
self .assertMarkdownRenders (
32
111
'' ,
33
112
'<p><img alt="x"x" src="x" /></p>'
34
113
)
35
114
36
- # TODO: Move rest of smarty tests here.
115
+ def test_code_spans (self ):
116
+ self .assertMarkdownRenders (
117
+ 'Skip `"code" -- --- \' spans\' ...`.' ,
118
+ '<p>Skip <code>"code" -- --- \' spans\' ...</code>.</p>'
119
+ )
120
+
121
+ def test_code_blocks (self ):
122
+ text = (
123
+ ' Also skip "code" \' blocks\' \n '
124
+ ' foo -- bar --- baz ...'
125
+ )
126
+ html = (
127
+ '<pre><code>Also skip "code" \' blocks\' \n '
128
+ 'foo -- bar --- baz ...\n '
129
+ '</code></pre>'
130
+ )
131
+ self .assertMarkdownRenders (text , html )
132
+
133
+ def test_horizontal_rule (self ):
134
+ self .assertMarkdownRenders ('--- -- ---' , '<hr />' )
135
+
136
+
137
+ class TestSmartyAngledQuotes (TestCase ):
138
+
139
+ default_kwargs = {
140
+ 'extensions' : ['smarty' ],
141
+ 'extension_configs' : {
142
+ 'smarty' : {
143
+ 'smart_angled_quotes' : True ,
144
+ },
145
+ },
146
+ }
147
+
148
+ def test_angled_quotes (self ):
149
+ self .assertMarkdownRenders (
150
+ '<<hello>>' ,
151
+ '<p>«hello»</p>'
152
+ )
153
+ self .assertMarkdownRenders (
154
+ 'Кавычки-<<ёлочки>>' ,
155
+ '<p>Кавычки-«ёлочки»</p>'
156
+ )
157
+ self .assertMarkdownRenders (
158
+ 'Anführungszeichen->>Chevrons<<' ,
159
+ '<p>Anführungszeichen-»Chevrons«</p>'
160
+ )
161
+
162
+
163
+ class TestSmartyCustomSubstitutions (TestCase ):
164
+
165
+ default_kwargs = {
166
+ 'extensions' : ['smarty' ],
167
+ 'extension_configs' : {
168
+ 'smarty' : {
169
+ 'smart_angled_quotes' : True ,
170
+ 'substitutions' : {
171
+ 'ndash' : '\u2013 ' ,
172
+ 'mdash' : '\u2014 ' ,
173
+ 'ellipsis' : '\u2026 ' ,
174
+ 'left-single-quote' : '‚' , # `sb` is not a typo!
175
+ 'right-single-quote' : '‘' ,
176
+ 'left-double-quote' : '„' ,
177
+ 'right-double-quote' : '“' ,
178
+ 'left-angle-quote' : '[' ,
179
+ 'right-angle-quote' : ']' ,
180
+ },
181
+ },
182
+ },
183
+ }
184
+
185
+ def test_custom_substitutions (self ):
186
+ text = (
187
+ '<< The "Unicode char of the year 2014"\n '
188
+ "is the 'mdash': ---\n "
189
+ "Must not be confused with 'ndash' (--) ... >>"
190
+ )
191
+ html = (
192
+ '<p>[ The „Unicode char of the year 2014“\n '
193
+ 'is the ‚mdash‘: \u2014 \n '
194
+ 'Must not be confused with ‚ndash‘ (\u2013 ) \u2026 ]</p>'
195
+ )
196
+ self .assertMarkdownRenders (text , html )
0 commit comments