Skip to content

Commit 82ac905

Browse files
committed
Properly parse processing instructions in md_in_html
Empty tags do not have a `mardkown` attribute set on them. Therefore, there is no need to check the mdstack to determine behavior. If we are in any md_in_html state (regardless of block, span, etc) the behavior is the same. Fixes #1070.
1 parent 81cc5b8 commit 82ac905

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

docs/change_log/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Python-Markdown Change Log
55

66
Under development: version 3.3.4 (a bug-fix release).
77

8+
* Properly parse processing instructions in md_in_html (#1070).
89
* Properly parse code spans in md_in_html (#1069).
910

1011
Oct 25, 2020: version 3.3.3 (a bug-fix release).

markdown/extensions/md_in_html.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ def handle_empty_tag(self, data, is_block):
204204
if self.at_line_start() and is_block:
205205
self.handle_data('\n' + self.md.htmlStash.store(data) + '\n\n')
206206
else:
207-
if self.mdstate and self.mdstate[-1] == "off":
208-
self.handle_data(self.md.htmlStash.store(data))
209-
else:
210-
self.handle_data(data)
207+
self.handle_data(self.md.htmlStash.store(data))
211208

212209

213210
class HtmlBlockPreprocessor(Preprocessor):

tests/test_syntax/extensions/test_md_in_html.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,56 @@ def test_md1_in_tail(self):
634634
)
635635
)
636636

637+
def test_md1_PI_oneliner(self):
638+
self.assertMarkdownRenders(
639+
'<div markdown="1"><?php print("foo"); ?></div>',
640+
self.dedent(
641+
"""
642+
<div>
643+
<?php print("foo"); ?>
644+
</div>
645+
"""
646+
)
647+
)
648+
649+
def test_md1_PI_multiline(self):
650+
self.assertMarkdownRenders(
651+
self.dedent(
652+
"""
653+
<div markdown="1">
654+
<?php print("foo"); ?>
655+
</div>
656+
"""
657+
),
658+
self.dedent(
659+
"""
660+
<div>
661+
<?php print("foo"); ?>
662+
</div>
663+
"""
664+
)
665+
)
666+
667+
def test_md1_PI_blank_lines(self):
668+
self.assertMarkdownRenders(
669+
self.dedent(
670+
"""
671+
<div markdown="1">
672+
673+
<?php print("foo"); ?>
674+
675+
</div>
676+
"""
677+
),
678+
self.dedent(
679+
"""
680+
<div>
681+
<?php print("foo"); ?>
682+
</div>
683+
"""
684+
)
685+
)
686+
637687
def test_md_span_paragraph(self):
638688
self.assertMarkdownRenders(
639689
'<p markdown="span">*foo*</p>',

0 commit comments

Comments
 (0)