Skip to content
Merged
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
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* DRY fix in `abbr` extension by introducing method `create_element` (#1483).

### Fixed

* Backslash Unescape IDs set via `attr_list` on `toc` (#1493).

## [3.7] -- 2024-08-16

### Changed
Expand Down
2 changes: 1 addition & 1 deletion markdown/extensions/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def run(self, doc: etree.Element) -> None:
if int(el.tag[-1]) >= self.toc_top and int(el.tag[-1]) <= self.toc_bottom:
toc_tokens.append({
'level': int(el.tag[-1]),
'id': el.attrib["id"],
'id': unescape(el.attrib["id"]),
'name': name,
'html': innerhtml,
'data-toc-label': data_toc_label
Expand Down
6 changes: 6 additions & 0 deletions tests/test_syntax/extensions/test_attr_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def test_unclosed_quote_ignored(self):
'<h1 foo="&quot;bar">Heading</h1>'
)

def test_backslash_escape_value(self):
self.assertMarkdownRenders(
'# `*Foo*` { id="\\*Foo\\*" }',
'<h1 id="*Foo*"><code>*Foo*</code></h1>'
)

def test_table_td(self):
self.assertMarkdownRenders(
self.dedent(
Expand Down
26 changes: 26 additions & 0 deletions tests/test_syntax/extensions/test_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,32 @@ def test_escaped_char_in_id(self):
extensions=['toc']
)

def test_escaped_char_in_attr_list(self):
self.assertMarkdownRenders(
r'# `*Foo*` { id="\*Foo\*" }',
'<h1 id="*Foo*"><code>*Foo*</code></h1>',
expected_attrs={
'toc': (
'<div class="toc">\n'
'<ul>\n' # noqa
'<li><a href="#*Foo*">*Foo*</a></li>\n' # noqa
'</ul>\n' # noqa
'</div>\n' # noqa
),
'toc_tokens': [
{
'level': 1,
'id': '*Foo*',
'name': '*Foo*',
'html': '<code>*Foo*</code>',
'data-toc-label': '',
'children': []
}
]
},
extensions=['toc', 'attr_list']
)

def testAutoLinkEmail(self):
self.assertMarkdownRenders(
'## <[email protected]>',
Expand Down
Loading