diff --git a/docs/changelog.md b/docs/changelog.md index 661161c6..1d8531a8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -12,6 +12,13 @@ and this project adheres to the [Python Version Specification](https://packaging.python.org/en/latest/specifications/version-specifiers/). See the [Contributing Guide](contributing.md) for details. +## [unreleased] + +### Fixed + +* Treat `picture` as a block-level HTML element so comments inside it do not + split the element into invalid paragraphs (#1643). + ## [3.11.0] - 2026-09-25 ### Changed diff --git a/docs/extensions/md_in_html.md b/docs/extensions/md_in_html.md index 13a9a88b..6181f1dc 100644 --- a/docs/extensions/md_in_html.md +++ b/docs/extensions/md_in_html.md @@ -45,8 +45,8 @@ When the `markdown` attribute is set to `"1"`, then the parser will use the defa The following tags have the `block` behavior by default: `article`, `aside`, `blockquote`, `body`, `colgroup`, `details`, `div`, `dl`, `fieldset`, `figcaption`, `figure`, `footer`, `form`, `group`, `header`, `hgroup`, `hr`, -`iframe`, `main`, `map`, `menu`, `nav`, `noscript`, `object`, `ol`, `output`, `progress`, `section`, `table`, -`tbody`, `tfoot`, `thead`, `tr`, `ul` and `video`. +`iframe`, `main`, `map`, `menu`, `nav`, `noscript`, `object`, `ol`, `output`, `picture`, `progress`, `section`, +`table`, `tbody`, `tfoot`, `thead`, `tr`, `ul` and `video`. For example: diff --git a/markdown/util.py b/markdown/util.py index 29ffa247..439e66dd 100644 --- a/markdown/util.py +++ b/markdown/util.py @@ -53,7 +53,7 @@ 'p', 'pre', 'section', 'table', 'ul', # Other elements which Markdown should not be mucking up the contents of. 'canvas', 'colgroup', 'dd', 'body', 'dt', 'group', 'html', 'iframe', 'li', 'legend', - 'math', 'map', 'noscript', 'output', 'object', 'option', 'progress', 'script', + 'math', 'map', 'noscript', 'output', 'object', 'option', 'picture', 'progress', 'script', 'style', 'summary', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'tr', 'video', 'center' ] diff --git a/tests/test_syntax/blocks/test_html_blocks.py b/tests/test_syntax/blocks/test_html_blocks.py index ecc10f45..52da2a10 100644 --- a/tests/test_syntax/blocks/test_html_blocks.py +++ b/tests/test_syntax/blocks/test_html_blocks.py @@ -1004,6 +1004,35 @@ def test_raw_comment_nested(self): ) ) + def test_raw_picture_with_comment(self): + # HTML comments inside must not split the element (see #1643). + self.assertMarkdownRenders( + self.dedent( + """ + + + + Example + + """ + ), + self.dedent( + """ + + + + Example + + """ + ) + ) + + def test_inline_picture_remains_inline(self): + self.assertMarkdownRenders( + 'See Example here.', + '

See Example here.

' + ) + def test_comment_in_code_block(self): self.assertMarkdownRenders( ' ',