diff --git a/docs/changelog.md b/docs/changelog.md index 5ae254627..5ca092b23 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 5462a906c..c92f928b6 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -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 diff --git a/tests/test_syntax/extensions/test_attr_list.py b/tests/test_syntax/extensions/test_attr_list.py index e9a10960f..1a0ae12c2 100644 --- a/tests/test_syntax/extensions/test_attr_list.py +++ b/tests/test_syntax/extensions/test_attr_list.py @@ -72,6 +72,12 @@ def test_unclosed_quote_ignored(self): '
*Foo*
*Foo*
*Foo*
',
+ 'data-toc-label': '',
+ 'children': []
+ }
+ ]
+ },
+ extensions=['toc', 'attr_list']
+ )
+
def testAutoLinkEmail(self):
self.assertMarkdownRenders(
'##