Skip to content

Add --print option to preview entries without markers - #4

Merged
Gulliby merged 2 commits into
mainfrom
feature/mdtoc-print
Oct 13, 2026
Merged

Gulliby merged 2 commits into
mainfrom
feature/mdtoc-print

Conversation

@Gulliby

@Gulliby Gulliby commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Requested by gulliby

Before

To look at the table-of-contents entries, you had to add the <!-- toc --> / <!-- tocstop --> marker pair to the file and read the result back.

After

--print writes the generated entries to stdout and never touches the file. No markers are needed; output uses LF line endings and nothing is printed when no heading is selected.

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

--print with --check, or with more than one file, exits 1 with a clear message.

How

  • src/cli.ts: --print option, the two conflict checks, usage/help text, print branch in main.
  • tests/print.test.ts: 15 new tests; tests/cli.test.ts: print: false added to three expected parseArgs objects.
  • README.md: new "Preview without markers" section and an options table row.

--print writes the generated entries to stdout, needs no marker pair and never modifies the file. It cannot be combined with --check and accepts exactly one file.
On macOS the temporary directory is a symlink, so an absolute path and a relative path to the same file did not match.
@Gulliby
Gulliby merged commit 833b651 into main Oct 13, 2026
6 checks passed
@Gulliby
Gulliby deleted the feature/mdtoc-print branch October 13, 2026 13:48
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