diff options
| author | Waylan Limberg <waylan.limberg@icloud.com> | 2021-02-24 14:20:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-24 14:20:29 -0500 |
| commit | 613ad502a4cf2293901e8f67690c198fc22c8f88 (patch) | |
| tree | 881dcb80d9a2ba31f6e7e72cccb932c05fc25d6f /markdown/extensions | |
| parent | 1858c1b601ead62ed49646ae0d99298f41b1a271 (diff) | |
| download | python-markdown-613ad502a4cf2293901e8f67690c198fc22c8f88.tar.gz | |
Ensure permalinks and ankorlinks are not restricted by toc_depth
This fixes a regression which was introduced with support for toc_depth.
Relevant tests have been moved and updated to the new framework.
Fixes #1107.
The test framework also received an addition. The assertMarkdownRenders
method now accepts a new keyword expected_attrs which consists of a dict
of attrs and expected values. Each is checked against the attr of the
Markdown instance. This was needed to check the value of md.toc and
md.toc_tokens in some of the included tests.
Diffstat (limited to 'markdown/extensions')
| -rw-r--r-- | markdown/extensions/toc.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index b2564c9..d64ec16 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -269,8 +269,6 @@ class TocTreeprocessor(Treeprocessor): for el in doc.iter(): if isinstance(el.tag, str) and self.header_rgx.match(el.tag): self.set_level(el) - if int(el.tag[-1]) < self.toc_top or int(el.tag[-1]) > self.toc_bottom: - continue text = get_name(el) # Do not override pre-existing ids @@ -278,14 +276,15 @@ class TocTreeprocessor(Treeprocessor): innertext = unescape(stashedHTML2text(text, self.md)) el.attrib["id"] = unique(self.slugify(innertext, self.sep), used_ids) - toc_tokens.append({ - 'level': int(el.tag[-1]), - 'id': el.attrib["id"], - 'name': unescape(stashedHTML2text( - code_escape(el.attrib.get('data-toc-label', text)), - self.md, strip_entities=False - )) - }) + 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"], + 'name': unescape(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 if 'data-toc-label' in el.attrib: |
