Skip to content

feat: Full support of min level via sections#368

Open
thompson-tomo wants to merge 5 commits into
thlorenz:masterfrom
thompson-tomo:support_sections
Open

feat: Full support of min level via sections#368
thompson-tomo wants to merge 5 commits into
thlorenz:masterfrom
thompson-tomo:support_sections

Conversation

@thompson-tomo

@thompson-tomo thompson-tomo commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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

@thompson-tomo thompson-tomo changed the title Refactor to extract sections Refactor to extract sections & support min level Jun 25, 2026
@thompson-tomo thompson-tomo changed the title Refactor to extract sections & support min level Full support of min level via sections Jun 25, 2026
@thompson-tomo thompson-tomo changed the title Full support of min level via sections feat: Full support of min level via sections Jun 26, 2026
@PeterDaveHello PeterDaveHello requested a review from Copilot June 27, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js and update marker/header processing to support minlevel-driven sections.
  • Refactor HTML header extraction in lib/get-html-headers.js to 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.

Comment thread lib/transform.js Outdated
Comment thread lib/transform.js
Comment thread lib/transform.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: specify minimum header level

2 participants