feat: Full support of min level via sections#368
Open
thompson-tomo wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds “min header level via sections” support to DocToc by grouping headers into sections derived from --minlevel, enabling subsection-only TOCs and introducing a guardrail when multiple sections are detected.
Changes:
- Implement section-building logic in
lib/transform.jsand update marker/header processing to support minlevel-driven sections. - Refactor HTML header extraction in
lib/get-html-headers.jsto return richer node/range info for downstream section logic. - Add/adjust tests and fixtures for minlevel behavior and the “multiple sections” warning case; update README docs.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
lib/transform.js |
Core implementation of section detection/grouping and minlevel-driven TOC generation behavior. |
lib/get-html-headers.js |
Refactors HTML header parsing to support the updated transform/section logic. |
doctoc.js |
Removes the --minlevel > 2 restriction so higher min levels are accepted. |
test/transform.js |
Adds a minlevel-focused transform test case. |
test/transform-stdout.js |
Adds a CLI test asserting the multi-section warning output. |
test/fixtures/readme-with-sections.md |
New fixture containing multiple sections (and front matter) for the CLI test. |
README.md |
Documents section-based behavior for --minlevel and the multi-section failure mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Closes: #140
Progresses: #78
This has the toc headers grouped into sections with the sections formed based on min level. In the case where multiple sections are found it exits, with stderr.
By grouping the headers into sections we can easily support sections in v3 and it provides an out of the box solution for handling the edge case of having multiple headers below the min level.
It is easier to review with whitespace off aka https://github.com/thlorenz/doctoc/pull/368/changes?w=1