feat(toc): add --depth option to limit heading level - #174
Merged
Merged
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.
Summary
Fixes #25: a way to keep only the top heading levels in the TOC.
--depth <NUM>keeps only headings with level<= NUM. The level is absolute, as--depthin github-markdown-toc.go:--depth 2keeps#and##. An empty value or0means no limit, which is the current behavior.gh-md-toc:gh_toc_grab: one condition at the start of the awk script shared by the defaultand OS/390 branches, so it applies to stdin, local files, remote URLs, several
inputs and
--insert. The value is passed withawk -vand compared as a number.gh_toc_app:--depthis parsed right after--indentand before-, in theexisting fixed order of options.
gh_tocgets it as a new last parameter.--help: a new line right after--indent.README.md: an example with--depth 1in "Local files", without a new heading,so the README TOC asserted in the tests does not change.
tests/tests.bats: tests for a local file (--depth 2) and stdin (--depth 1 -)with a new fixture
tests/test directory/test_depth.md;test_helpupdated.openspec/changes/add-toc-depth: proposal, design, spec and tasks.Not included:
--start-depth, the--depth=NUMsyntax, validation of the value,changes to indentation (#30, #75), options in any order.
Testing
--depth 0gives the same output as without the option.--depth 1and--insertwith--depth 1.make lintpasses.