Repository navigation
Fix invalid TOC HTML when a header is above the first header's level - #754
Open
Enesuygurs wants to merge 2 commits into
Open
Enesuygurs wants to merge 2 commits into
Enesuygurs wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the
tocextra, a document whose first header isn't its highest-level one produces broken TOC HTML. For example,## Overview,# Getting Started,## Installgives:The outer list closes straight away, a stray
</li>is left behind, and everything after it ends up outside any list.A related problem shows up when a level is skipped and the document later returns to it.
# A,### B,## C,## Dputs C next to A at the top level and nests D under C, although both are h2s under A.calculate_toc_htmlcompared the new header with the current list's level instead of its parent's, and it could close the outermost list. It now closes a nested list only when the header belongs at or above the parent's level; otherwise the header stays in the current list. The outermost list is never closed early, so a header above the first one's level becomes another top-level entry. Properly nested documents give the same output as before, and unlike #337 this doesn't add extra nested lists for skipped levels.The nesting now matches Python-Markdown's toc extension: I compared 20,000 random header sequences against its
toc_tokens, and all of them match and are well-formed.I added the
toc_shallower_headerstest case, which fails on master.make testoneandmake testredospass.