Skip to content

Add --min-depth option to skip shallow headings - #2

Merged
Gulliby merged 1 commit into
mainfrom
feature/min-depth
Oct 12, 2026
Merged

Gulliby merged 1 commit into
mainfrom
feature/min-depth

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Before

mdtoc always started the table of contents at level 1, so a page title (# Title) always appeared as the top entry. Only --max-depth was available.

After

--min-depth <1-6> (default 1) skips heading levels above the given depth. Entries are indented relative to the selected minimum, and duplicate-heading anchors are still numbered over all headings.

bun run src/cli.ts --min-depth 2 README.md
bun run src/cli.ts --check --min-depth 2 README.md

It combines with --max-depth (--min-depth 3 --max-depth 3 lists only level 3). Invalid values (0, 7, non-numbers, empty, or a minimum above the maximum) exit 1 with a clear message and leave the file unchanged.

How

  • src/toc.ts: depth filtering and relative indentation.
  • src/cli.ts: option parsing, validation and help text.
  • README.md: documentation, example and options table row.
  • Tests: tests/cli.test.ts (13 new tests; 93 pass, typecheck and lint are clean).

@Gulliby
Gulliby merged commit 612b459 into main Oct 12, 2026
6 checks passed
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.

1 participant