-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use toc_tokens to generate the TOC #1970
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
Conversation
waylan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start. I've noted a few things below.
|
While working on this, I noticed that Python-Markdown doesn't correctly un-stash HTML for |
aeb5dac to
9914fb1
Compare
This means that we will need to require the most recent version of Markdown. Traditionally we have supported much older Markdown versions. I wonder if we should leave the old HTML to TOC parser as a fallback. If the new version of Markdown is installed, use the On the other hand, we could just update the required version in One or the other needs to happen. Either way, it should be part of this PR. Let's see what happens with the Markdown fix first. |
A third option would be to manually strip out the stashed HTML placeholders from |
|
Did you close this intentionally? I thought this was a good start Sent with GitHawk |
|
Whoops, I think I unintentionally deleted this branch when I was cleaning up my repo. Let's see if I can undo that... |
|
FYI, Markdown 3.2 has just been released, which includes the fix this is waiting for (Python-Markdown/markdown#901). |
|
Cool, I'll work on finishing this up, hopefully by the end of the weekend. @waylan, if you're still concerned about requiring the latest version of Python-Markdown in MkDocs, I could work around that by stripping the stashed HTML placeholders from the TOC object. It should just be a simple regex. I'd prefer (not strongly) to just require Python-Markdown 3.2 though. |
|
Requiring Markdown 3.2 is fine. As it turns out, the upcoming release of MkDocs and Markdown 3.2 are both the first versions to drop support for Python 2.7, so it makes sense that MkDocs updates it's dependency anyway. |
|
@waylan Ok, this is mostly good. I did notice one weird thing that's causing a test failure though: if you have a header like This seems like a bug in Python-Markdown, since it does strip Markdown inside the header for |
Yes, it is. I've reported it at Python-Markdown/markdown#906. |
|
Python-Markdown 3.2.1 was just released with a fix for the escaping issue. That needs to be the minimum version supported by MkDocs now. |
d36347e to
f8c9343
Compare
This patch improves the consistency of TOC levels, so now the level is always equal to the N in the `<hN>` tag. It also allows users of the MkDocs theme to set the navigation depth to show in the TOC panel (defaulting to 2).
f8c9343 to
71db354
Compare
|
@jimporter this looks good. Awesome job. I just want to make sure the change to have TOC items being 1-indexed is not going to be a problem for third party themes. @squidfunk do you have any input on this? The idea is that the TOC level attribute will now always match |
|
@waylan it’s been a long time but I have a hack in place that detects whether there is an |
|
@squidfunk thanks for the feedback. And we're glad to provide a useful feature. |
This needs more testing, but once it's done, this should resolve both #1910 and #770. I've tried to maintain backward compatibility here, though maybe it makes sense to change the meaning of
level. Currently, it's 0-indexed, but it might be better to make it 1-indexed so that the level matches N in<hN>for the headers.