Skip to content

Add --exclude option to leave out headings - #3

Merged
Gulliby merged 1 commit into
mainfrom
feature/exclude-headings
Oct 13, 2026
Merged

Gulliby merged 1 commit into
mainfrom
feature/exclude-headings

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Before

mdtoc always listed every heading it found. There was no way to keep a heading such as License out of the table of contents.

After

--exclude TEXT leaves out every heading whose visible text is exactly TEXT (case-sensitive, surrounding spaces trimmed). The option can be repeated. Sub-headings stay, and anchors are still counted over all headings, so links such as #usage-1 stay correct.

bun run src/cli.ts --min-depth 2 --exclude License README.md
- [Installation](#installation)
- [Usage](#usage)
  - [Sub](#sub)

An empty value (--exclude "", a missing value, --exclude=) is rejected with mdtoc: --exclude requires a non-empty heading text. and exit code 1. It works with --check.

How

  • src/cli.ts: parses the repeatable --exclude option and passes it on.
  • src/toc.ts: filters excluded headings when generating the table of contents, after anchors are computed.
  • tests/cli.test.ts: 14 new tests (repeats, trimming, Setext and inline formatting, anchors, errors, excluding everything); one existing test was renamed to also cover the help text.
  • README.md: new "Leave out headings" section and an options table row.

Headings whose text matches are left out of the generated table of contents. Anchors are still counted over all headings, so links stay correct.
@Gulliby
Gulliby merged commit bb17472 into main Oct 13, 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