toc: add max_level option to limit which heading levels get anchor links#1567
toc: add max_level option to limit which heading levels get anchor links#1567rundef wants to merge 4 commits intoPython-Markdown:masterfrom
max_level option to limit which heading levels get anchor links#1567Conversation
|
Interesting. This is not a feature I would have ever considered. In fact, I am always frustrated when a site I am linking to does not give me more granular anchors to link to. I'm tempted to reject this for that pet-peeve alone, but recognize that there could be other factors. A stronger objection might be to avoid feature creep. So, can you make a case for why this should be included? Assuming this does get accepted, another concern is the name of the option. "Max" seems illogical from a certain perspective. In fact, the proposed docs state "highest heading level (deepest |
|
Thanks for the review, here's my use case:
I suppose there must be other projects that use I thought it would be a good idea to give more control to documentation/blog authors in general |
Why is it "not desirable?" This would annoy me. I want to link to the specific sentence I am referencing (or as close to it as possible). But if there are 3 Regardless, for this to be approved it would need to pass all tests. For example, we don't use abbreviations in the prose in our documentation. When referring to the You would also need to add an entry to the changelog. See the Contributing Guide for details. ... See, isn't that helpful that I was able to link to the |
|
it's ok I'll just use my fork |
The TOC extension previously hardcoded anchor insertion for
<h1>–<h6>viaself.header_rgx = re.compile("[Hh][123456]"). This patch introduces a configurablemax_levelparameter, allowing users to restrict anchor links(permalinks) to headings up to a specific level (default = 6).
Example:
TocExtension(anchorlink=True, max_level=2)adds anchors only to<h1>and<h2>elements.