Repository navigation
fix(toc): indent TOC entries relative to the top heading level - #180
Merged
Merged
Conversation
Without a level 1 heading the first TOC entry got (level-1)*indent spaces, and with 4 or more spaces GitHub rendered the whole TOC as a code block. Entries are now indented by (level-min_level)*indent, where min_level is the smallest heading level of the document. Output for documents with a level 1 heading is unchanged. Fixes #30
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 #30: the indent of a TOC entry was
(level - 1) * indentspaces, counted from#even when the document has no#heading. When the first entry got 4 or morespaces, GitHub rendered the whole TOC as a code block:
###/####with the default indent: 6 spaces before the first entry (also with--insert).##/###with--indent 4: 4 spaces before the first entry.gh-md-toc: the awk script ingh_toc_grabkeeps the entries and prints them in anENDblock with(level - min_level) * indentspaces, wheremin_levelis thesmallest heading level of the document. The
ENDblock is added to both awkbranches (default and OS/390). Each input of several inputs has its own
min_level.--depthstays absolute,--numberedneeds no changes.tests/: new fixturetest_noh1.mdwithout a#heading and three tests: localfile, stdin with
--indent 4, stdin with--depth 2.openspec/changes/fix-relative-toc-indent: proposal, design, tasks, a newtoc-indentspec and deltas forremote-toc,toc-depth,toc-numbered, whichstated
(level - 1) * indent.Output for documents with a
#heading is byte-for-byte the same, so no existingassertions changed. For a document without a
#heading, a TOC that--insertputthere earlier changes on the next run.
Not covered: a document whose first heading is deeper than a later one (e.g.
###before
##) with--indent 4or more still gets a code block.Testing
make lintpasses.<ul>with the GitHub markdown API, not<pre><code>.