diff options
| author | Waylan Limberg <waylan.limberg@icloud.com> | 2022-07-15 08:38:34 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-15 08:38:34 -0400 |
| commit | c0f6e5a31ea8e7fe98910a0523144c2a96fa9bf1 (patch) | |
| tree | 5686120668ce35073d08e08a366d6d3371ab2b17 /markdown/extensions | |
| parent | 77fb7f1b51076becff488a9b42ef2883153262a0 (diff) | |
| download | python-markdown-c0f6e5a31ea8e7fe98910a0523144c2a96fa9bf1.tar.gz | |
Move backslash unescaping to treeprocessor
By unescaping backslash escapes in a treeprocessor, the text is properly
escaped during serialization. Fixes #1131.
As it is recognized that various third-party extensions may be calling the
old class at `postprocessors.UnescapePostprocessor` the old class remains
in the codebase, but has been deprecated and will be removed in a future
release. The new class `treeprocessors.UnescapeTreeprocessor` should be
used instead.
Diffstat (limited to 'markdown/extensions')
| -rw-r--r-- | markdown/extensions/toc.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 80138b3..1ded18d 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -16,7 +16,7 @@ License: [BSD](https://opensource.org/licenses/bsd-license.php) from . import Extension from ..treeprocessors import Treeprocessor from ..util import code_escape, parseBoolValue, AMP_SUBSTITUTE, HTML_PLACEHOLDER_RE, AtomicString -from ..postprocessors import UnescapePostprocessor +from ..treeprocessors import UnescapeTreeprocessor import re import html import unicodedata @@ -84,8 +84,8 @@ def stashedHTML2text(text, md, strip_entities=True): def unescape(text): """ Unescape escaped text. """ - c = UnescapePostprocessor() - return c.run(text) + c = UnescapeTreeprocessor() + return c.unescape(text) def nest_toc_tokens(toc_list): @@ -289,10 +289,10 @@ class TocTreeprocessor(Treeprocessor): toc_tokens.append({ 'level': int(el.tag[-1]), 'id': el.attrib["id"], - 'name': unescape(stashedHTML2text( + 'name': stashedHTML2text( code_escape(el.attrib.get('data-toc-label', text)), self.md, strip_entities=False - )) + ) }) # Remove the data-toc-label attribute as it is no longer needed |
