Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/extensions/md_in_html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion markdown/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down
29 changes: 29 additions & 0 deletions tests/test_syntax/blocks/test_html_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,35 @@ def test_raw_comment_nested(self):
)
)

def test_raw_picture_with_comment(self):
# HTML comments inside <picture> must not split the element (see #1643).
self.assertMarkdownRenders(
self.dedent(
"""
<picture>
<!-- comment -->
<source media="(prefers-color-scheme: dark)" srcset="dark.svg">
<img alt="Example" src="example.svg">
</picture>
"""
),
self.dedent(
"""
<picture>
<!-- comment -->
<source media="(prefers-color-scheme: dark)" srcset="dark.svg">
<img alt="Example" src="example.svg">
</picture>
"""
)
)

def test_inline_picture_remains_inline(self):
self.assertMarkdownRenders(
'See <picture><img alt="Example" src="x.svg"></picture> here.',
'<p>See <picture><img alt="Example" src="x.svg"></picture> here.</p>'
)

def test_comment_in_code_block(self):
self.assertMarkdownRenders(
' <!-- *foo* -->',
Expand Down