File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -152,13 +152,12 @@ def is_nested_node(el):
152
152
def process_text (self , el ):
153
153
text = six .text_type (el ) or ''
154
154
155
- # dont remove any whitespace when handling pre or code in pre
156
- if not (el .parent .name == 'pre'
157
- or (el .parent .name == 'code'
158
- and el .parent .parent .name == 'pre' )):
155
+ # normalize whitespace if we're not inside a preformatted element
156
+ if not el .find_parent ('pre' ):
159
157
text = whitespace_re .sub (' ' , text )
160
158
161
- if el .parent .name != 'code' and el .parent .name != 'pre' :
159
+ # escape special characters if we're not inside a preformatted or code element
160
+ if not el .find_parent (['pre' , 'code' , 'kbd' , 'samp' ]):
162
161
text = self .escape (text )
163
162
164
163
# remove trailing whitespaces if any of the following condition is true:
Original file line number Diff line number Diff line change @@ -70,7 +70,12 @@ def test_br():
70
70
71
71
def test_code ():
72
72
inline_tests ('code' , '`' )
73
- assert md ('<code>this_should_not_escape</code>' ) == '`this_should_not_escape`'
73
+ assert md ('<code>*this_should_not_escape*</code>' ) == '`*this_should_not_escape*`'
74
+ assert md ('<kbd>*this_should_not_escape*</kbd>' ) == '`*this_should_not_escape*`'
75
+ assert md ('<samp>*this_should_not_escape*</samp>' ) == '`*this_should_not_escape*`'
76
+ assert md ('<code><span>*this_should_not_escape*</span></code>' ) == '`*this_should_not_escape*`'
77
+ assert md ('<code>this should\t \t normalize</code>' ) == '`this should normalize`'
78
+ assert md ('<code><span>this should\t \t normalize</span></code>' ) == '`this should normalize`'
74
79
75
80
76
81
def test_del ():
@@ -187,7 +192,10 @@ def test_p():
187
192
def test_pre ():
188
193
assert md ('<pre>test\n foo\n bar</pre>' ) == '\n ```\n test\n foo\n bar\n ```\n '
189
194
assert md ('<pre><code>test\n foo\n bar</code></pre>' ) == '\n ```\n test\n foo\n bar\n ```\n '
190
- assert md ('<pre>this_should_not_escape</pre>' ) == '\n ```\n this_should_not_escape\n ```\n '
195
+ assert md ('<pre>*this_should_not_escape*</pre>' ) == '\n ```\n *this_should_not_escape*\n ```\n '
196
+ assert md ('<pre><span>*this_should_not_escape*</span></pre>' ) == '\n ```\n *this_should_not_escape*\n ```\n '
197
+ assert md ('<pre>\t \t this should\t \t not normalize</pre>' ) == '\n ```\n \t \t this should\t \t not normalize\n ```\n '
198
+ assert md ('<pre><span>\t \t this should\t \t not normalize</span></pre>' ) == '\n ```\n \t \t this should\t \t not normalize\n ```\n '
191
199
192
200
193
201
def test_s ():
You can’t perform that action at this time.
0 commit comments