Repository navigation
feat(toc): warn about headings that skip a level - #187
Merged
Merged
Conversation
Fixes #75. When a heading skips a level (`# First` followed by `### Third`), GitHub renders its TOC entry as text of the parent entry, on one line. The TOC does not change; for every such entry a warning goes to stderr: `Warning: heading 'Third' (level 3) skips a level after 'First' (level 1), see https://github.com/ekalinin/github-markdown-toc/issues/75`
This was referenced Oct 30, 2026
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.
Summary
Fixes #75: when a heading skips a level (
# Firstfollowed by### Third), GitHubrenders its TOC entry as text of the parent entry, on one line (
First * Third).The TOC does not change. For every TOC entry whose heading level is more than one level
deeper than its parent, a line goes to stderr:
How GitHub renders a skipped level today (checked with the markdown API):
#->####->####***1.gh-md-toc(common_awk_scriptingh_toc_grab, shared by the default and OS/390branches):
--numbered outlinenumbers use: the check runs right after the stack of outlinenumbers pops down to it. Entries without a parent (
###before##) get nowarning. With
--depth, only the entries in the TOC are checked.| "cat 1>&2"(POSIX), so it never ends up inthe TOC that
--insertwrites or in the output of--stdout. The exit code doesnot change.
tests/test directory/test_numbered.md: Warning: ....tests/tests.bats: 7 new tests (#75). batsrunmerges stderr intolines, sothe three existing tests on
test_numbered.mdnow run gh-md-toc through a new helperwithout stderr; their assertions do not change.
openspec: theadd-skipped-level-warningchange (proposal, design, specs, tasks),not archived yet.
Not included: a change of the TOC for skipped levels (an indent by the depth in the
heading tree, or placeholder entries for the missing levels); a warning only when GitHub
actually renders the TOC wrong (with
--indent 2or--numbered list, one skippedlevel is still rendered as a nested list, and the warning is printed anyway); a document
whose first heading is deeper than a later one with
--indent 4or more; an option toturn the warning off.
Testing
BSD awk 20200816).
README.md, every fixture, theprintfinputs from the spec and the fourremote pages from the
remote-tocspec is byte-for-byte the same as with the scriptfrom
master; stderr is empty for all of them excepttest_numbered.mdand theprintfinputs.make lintpasses.