diff options
| author | Isaac Muse <faceless.shop@gmail.com> | 2020-04-06 09:40:56 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-06 11:40:56 -0400 |
| commit | ada40c6619fd0be740af646b043937e560716c95 (patch) | |
| tree | 23acd9542f62070ad5bf78e48ffc9c0113973592 /markdown/extensions | |
| parent | 7c595e28491d3cca28bc9901bb099bca8bcf4626 (diff) | |
| download | python-markdown-ada40c6619fd0be740af646b043937e560716c95.tar.gz | |
TOC fix for AtomicString handling (#934)
Fixes #931.
Diffstat (limited to 'markdown/extensions')
| -rw-r--r-- | markdown/extensions/toc.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 8f2b13f..b6cdc73 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -15,9 +15,10 @@ 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 +from ..util import code_escape, parseBoolValue, AMP_SUBSTITUTE, HTML_PLACEHOLDER_RE, AtomicString from ..postprocessors import UnescapePostprocessor import re +import html import unicodedata import xml.etree.ElementTree as etree @@ -44,6 +45,18 @@ def unique(id, ids): return id +def get_name(el): + """Get title name.""" + + text = [] + for c in el.itertext(): + if isinstance(c, AtomicString): + text.append(html.unescape(c)) + else: + text.append(c) + return ''.join(text).strip() + + def stashedHTML2text(text, md, strip_entities=True): """ Extract raw HTML from stash, reduce to plain text and swap with placeholder. """ def _html_sub(m): @@ -253,7 +266,7 @@ class TocTreeprocessor(Treeprocessor): self.set_level(el) if int(el.tag[-1]) < self.toc_top or int(el.tag[-1]) > self.toc_bottom: continue - text = ''.join(el.itertext()).strip() + text = get_name(el) # Do not override pre-existing ids if "id" not in el.attrib: |
