Skip to content

Commit 0c9a459

Browse files
committed
Handle HTML in multi-line inline code
1 parent 724de8c commit 0c9a459

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

markdown/extensions/md_in_html.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,12 @@ def handle_empty_tag(self, data, is_block):
253253
if self.inraw or not self.mdstack:
254254
super().handle_empty_tag(data, is_block)
255255
else:
256-
if self.at_line_start() or self.intail:
257-
if is_block:
258-
self.handle_data('\n' + self.md.htmlStash.store(data) + '\n\n')
259-
else:
260-
self.handle_data(self.md.htmlStash.store(data))
256+
if self.at_line_start() and is_block:
257+
self.handle_data('\n' + self.md.htmlStash.store(data) + '\n\n')
258+
elif self.mdstate and self.mdstate[-1] == "off":
259+
self.handle_data(self.md.htmlStash.store(data))
261260
else:
262-
self.treebuilder.data(data)
261+
self.handle_data(data)
263262

264263
def parse_pi(self, i: int) -> int:
265264
if self.at_line_start() or self.intail or self.mdstack:

tests/test_syntax/extensions/test_md_in_html.py

+45-4
Original file line numberDiff line numberDiff line change
@@ -1214,26 +1214,67 @@ def test_md1_code_void_tag(self):
12141214
"""
12151215
<div class="outer" markdown="1">
12161216
1217-
Code: `<label></input></label>`
1217+
Code: `<label><input/></label>`
12181218
12191219
</div>
12201220
12211221
<div class="outer" markdown="1">
12221222
1223-
HTML: <label></input></label>
1223+
HTML: <label><input/></label>
12241224
12251225
</div>
12261226
"""
12271227
),
12281228
'<div class="outer">\n'
1229-
'<p>Code: <code>&lt;label&gt;&lt;/input&gt;&lt;/label&gt;</code></p>\n'
1229+
'<p>Code: <code>&lt;label&gt;&lt;input/&gt;&lt;/label&gt;</code></p>\n'
12301230
'</div>\n'
12311231
'<div class="outer">\n'
1232-
'<p>HTML: <label></input></label></p>\n'
1232+
'<p>HTML: <label><input/></label></p>\n'
12331233
'</div>',
12341234
extensions=['md_in_html']
12351235
)
12361236

1237+
def test_md1_code_void_tag_multiline(self):
1238+
1239+
# https://github.com/Python-Markdown/markdown/issues/1075
1240+
self.assertMarkdownRenders(
1241+
self.dedent(
1242+
"""
1243+
<div class="outer" markdown="1">
1244+
1245+
Code: `
1246+
<label>
1247+
<input/>
1248+
</label>
1249+
`
1250+
1251+
</div>
1252+
1253+
<div class="outer" markdown="1">
1254+
1255+
HTML:
1256+
<label>
1257+
<input/>
1258+
</label>
1259+
1260+
</div>
1261+
"""
1262+
),
1263+
'<div class="outer">\n'
1264+
'<p>Code: <code>&lt;label&gt;\n'
1265+
'&lt;input/&gt;\n'
1266+
'&lt;/label&gt;</code></p>\n'
1267+
'</div>\n'
1268+
'<div class="outer">\n'
1269+
'<p>HTML:\n'
1270+
'<label>\n'
1271+
'<input/>\n'
1272+
'</label></p>\n'
1273+
'</div>',
1274+
extensions=['md_in_html']
1275+
)
1276+
1277+
12371278
def test_md1_code_comment(self):
12381279

12391280
self.assertMarkdownRenders(

0 commit comments

Comments
 (0)