Skip to content

Add --insert option to add the marker pair - #5

Merged
Gulliby merged 1 commit into
mainfrom
feature/insert-markers
Oct 15, 2026
Merged

Gulliby merged 1 commit into
mainfrom
feature/insert-markers

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Requested by gulliby

Before

A file without the <!-- toc --> / <!-- tocstop --> markers was an error, so the first table of contents of a new README had to be started by hand.

After

mdtoc --insert FILE adds the marker pair directly after the first level-1 ATX heading outside code fences (or at the start of the file when there is none) and then generates the entries. Files that already have markers are refreshed as before, so the command is safe to repeat; a file with only one marker is still an error. --insert cannot be combined with --check or --print.

bun run src/cli.ts --insert NOTES.md
# Guide
<!-- toc -->
- [Guide](#guide)
  - [Installation](#installation)
  - [Usage](#usage)
<!-- tocstop -->

## Installation

## Usage

How

  • src/toc.ts: new exported insertMarkers; the fence scanning is shared with extractHeadings.
  • src/cli.ts: the --insert option, its two conflicts, the usage text and the call.
  • tests/insert.test.ts: new tests (158 tests pass in all); tests/print.test.ts only has the usage line updated.
  • README.md: option row, "Add the markers" section, updated missing-markers sentence.

@Gulliby
Gulliby merged commit 42fa1b1 into main Oct 15, 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