Skip to content

Commit ff88261

Browse files
committed
Unescape backslash escaped TOC token names
Fixes #1360.
1 parent d60c16f commit ff88261

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

docs/change_log/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Python-Markdown Change Log
77

88
* Add a special case for initial 's to smarty extension (#1305).
99
* Unescape any backslash escaped inline raw HTML (#1358).
10+
* Unescape backslash escaped TOC token names (#1360).
1011

1112
March 23, 2023: version 3.4.3 (a bug-fix release).
1213

markdown/extensions/toc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ def run(self, doc):
289289
toc_tokens.append({
290290
'level': int(el.tag[-1]),
291291
'id': el.attrib["id"],
292-
'name': stashedHTML2text(
292+
'name': unescape(stashedHTML2text(
293293
code_escape(el.attrib.get('data-toc-label', text)),
294294
self.md, strip_entities=False
295-
)
295+
))
296296
})
297297

298298
# Remove the data-toc-label attribute as it is no longer needed

tests/test_syntax/extensions/test_toc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,23 @@ def test_escaped_char_in_id(self):
442442
self.assertMarkdownRenders(
443443
r'# escaped\_character',
444444
'<h1 id="escaped_character">escaped_character</h1>',
445+
expected_attrs={
446+
'toc': (
447+
'<div class="toc">\n'
448+
'<ul>\n' # noqa
449+
'<li><a href="#escaped_character">escaped_character</a></li>\n' # noqa
450+
'</ul>\n' # noqa
451+
'</div>\n' # noqa
452+
),
453+
'toc_tokens': [
454+
{
455+
'level': 1,
456+
'id': 'escaped_character',
457+
'name': 'escaped_character',
458+
'children': []
459+
}
460+
]
461+
},
445462
extensions=['toc']
446463
)
447464

0 commit comments

Comments
 (0)