-
Notifications
You must be signed in to change notification settings - Fork 875
TOC: Include permalink for headers out of toc_depth range #1107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well that's not how I thought things worked. I was about to say we already do what you are requesting, but checked first. >>> import markdown
>>> from markdown.extensions.toc import TocExtension
>>> src = '''
... # Level 1
...
... ## Level 2
...
... ### Level 3
...
... #### Level 4
...
... ##### Level 5
...
... ###### Level 6
... '''
>>> md = markdown.Markdown(extensions=[TocExtension(permalink=True, toc_depth='2-4')])
>>> print(md.convert(src))
<h1>Level 1</h1>
<h2 id="level-2">Level 2<a class="headerlink" href="#level-2" title="Permanent link">¶</a></h2>
<h3 id="level-3">Level 3<a class="headerlink" href="#level-3" title="Permanent link">¶</a></h3>
<h4 id="level-4">Level 4<a class="headerlink" href="#level-4" title="Permanent link">¶</a></h4>
<h5>Level 5</h5>
<h6>Level 6</h6>
>>> md.toc_tokens
[{'level': 2, 'id': 'level-2', 'name': 'Level 2', 'children': [{'level': 3, 'id': 'level-3', 'name': 'Level 3', 'children': [{'level': 4, 'id': 'level-4', 'name': 'Level 4', 'children': []}]}]}] I don't think I ever intended to have that behavior. I would expect IDs and permalinks to be applied to all levels regardless of which levels are included in the TOC. And yet, that is clearly not the behavior we have now and the existing behavior is included in a few tests. I think we should make this change. I would consider the existing behavior a regression. |
Funny enough, this is explicitly documented in the docs for Material for MkDocs. Not sure if @squidfunk has a stance on this behavior if the default changes.
|
We don't explicitly document this behavior. I checked the old PRs and issues addressing the code involved and I didn't find any discussion of the behavior for or against. I don't recall as it has been six years, but I'm assuming that I missed the change when I merged the PR provided by a third-party contributor. |
This fixes a regression which was introduced with support for toc_depth. Relevant tests have been moved and updated to the new framework. Fixes Python-Markdown#1107. The test fraamework 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.
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.
The reported behavior has been changed in #1108 and a new release has been made (3.3.4). Also, I filed a bug report at |
We need a version of Python markdown that fixes the following bug: Python-Markdown/markdown#1107 This version isn't available through apt, but can be installed through pip. Signed-off-by: Ruth Fuchss <[email protected]>
We need a version of Python markdown that fixes the following bug: Python-Markdown/markdown#1107 This version isn't available through apt, but can be installed through pip. Signed-off-by: Ruth Fuchss <[email protected]>
We need a version of Python markdown that fixes the following bug: Python-Markdown/markdown#1107 This version isn't available through apt, but can be installed through pip. Signed-off-by: Ruth Fuchss <[email protected]>
I would like to be able to enable permalinks for headers out of the
toc_depth
range. Currently only headers within the range get permalinks whenpermalink
is enabled. (Markdown==3.3.3
)My use case is that I have pages that have a lot of headers. In order for the TOC to be not too large, I use
toc_depth
to only include higher levels in my TOC. However, I would like users to still be able to directly link to the out-of-range headers if they need to.More concretely, I have API documentation for modules. My TOC only goes down to class names, as including method names would be too much, but I'd still like users to be able to link directly to method headers.
The text was updated successfully, but these errors were encountered: