You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At this time, no, there is no way to get the header level (hn) from the TOC. MkDocs uses Python-Markdown's toc extension to generate the TOC and that extension does not preserve the header level in the HTML it generates. Therefore, that information is not available for MkDocs to use (MkDocs parses the HTML TOC and builds a data object which is passed on to the template).
That said, Python-Markdown recently updated the toc extension to also provide toc_tokens (a list if dicts) and that does preserve the header level. We could adapt MkDocs to make use of that, which would probably be better than parsing the HTML TOC anyway. This is something I've been meaning to explore, but just haven't had the time to get to. Of course, a PR is always welcome.
Thanks for your feedback.
I see that starting with python-markdown 3.0, it also includes a parameter 'toc_depth' who would allow a better control than 'navigation_depth' (since it allow restricting by range) and could be nice to benefit from it too.
Regards
waylan
changed the title
[TOC] Anyway to have the real "level" of a toc_item ?
Use TOC Extension's new toc_tokens to build TOC
Nov 26, 2019
Hi Mkdocs,
It seems that the attribute "level" for page.toc items is not the level of the "hx" in the markdown documents but the "global" level
With a title :
If there is not title :
Is there anyway to get the real level of headings ?
Regards,
The text was updated successfully, but these errors were encountered: