diff --git a/markdown/extensions/md_in_html.py b/markdown/extensions/md_in_html.py index 174224ab9..39b77f719 100644 --- a/markdown/extensions/md_in_html.py +++ b/markdown/extensions/md_in_html.py @@ -93,7 +93,7 @@ def handle_starttag(self, tag, attrs): attrs = {key: value if value is not None else key for key, value in attrs} state = self.get_state(tag, attrs) - if self.inraw or (state in [None, 'off'] and not self.mdstack): + if self.inraw or (state in [None, 'off'] and not self.mdstack) or not self.at_line_start(): # fall back to default behavior attrs.pop('markdown', None) super().handle_starttag(tag, attrs) diff --git a/tests/test_syntax/extensions/test_md_in_html.py b/tests/test_syntax/extensions/test_md_in_html.py index 433cdd559..38020f1b4 100644 --- a/tests/test_syntax/extensions/test_md_in_html.py +++ b/tests/test_syntax/extensions/test_md_in_html.py @@ -390,6 +390,52 @@ def test_md1_nested_empty_block(self): ) ) + def test_md1_no_blank_line_before(self): + self.assertMarkdownRenders( + self.dedent( + """ + A _Markdown_ paragraph with no blank line after. +
+ A _Markdown_ paragraph in an HTML block with no blank line before. +
+ """ + ), + self.dedent( + """ +

A Markdown paragraph with no blank line after.

+
+

A Markdown paragraph in an HTML block with no blank line before.

+
+ """ + ) + ) + + def test_md1_no_line_break(self): + # The div here is parsed as a span-level element. Bad input equals bad output! + self.assertMarkdownRenders( + 'A _Markdown_ paragraph with
no _line break_.
', + '

A Markdown paragraph with

no line break.

' + ) + + def test_md1_in_tail(self): + self.assertMarkdownRenders( + self.dedent( + """ +
+ A _Markdown_ paragraph in an HTML block in tail of previous element. +
+ """ + ), + self.dedent( + """ +
+
+

A Markdown paragraph in an HTML block in tail of previous element.

+
+ """ + ) + ) + def test_md_span_paragraph(self): self.assertMarkdownRenders( '

*foo*

',