Skip to content

Commit 4d3ed63

Browse files
committed
feat: integrate toc command into CLI
Add toc command to main CLI with comprehensive options: - File pattern support with globs - Depth range configuration (min/max heading levels) - Multiple insertion positions - TOC customization options - Line numbers and custom markers - Help text with examples
1 parent fde93e0 commit 4d3ed63

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/cli.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { joinCommand } from './commands/join.js';
77
import { mergeCommand } from './commands/merge.js';
88
import { moveCommand } from './commands/move.js';
99
import { splitCommand } from './commands/split.js';
10+
import { tocCommand } from './commands/toc.js';
1011
import { validateCommand } from './commands/validate.js';
1112

1213
const program = new Command();
@@ -216,6 +217,46 @@ Note: This is an alias for the 'index' command with barrel-focused terminology.`
216217
)
217218
.action(indexCommand);
218219

220+
program
221+
.command('toc')
222+
.description('Generate and insert table of contents into markdown files')
223+
.argument('<files...>', 'Markdown files to process (supports globs like *.md, **/*.md)')
224+
.option('--min-depth <number>', 'Minimum heading level to include (1-6)', parseInt, 1)
225+
.option('--max-depth <number>', 'Maximum heading level to include (1-6)', parseInt, 6)
226+
.option('--include-line-numbers', 'Include line numbers in TOC entries')
227+
.option('--position <position>', 'TOC position: top|after-title|before-content|replace', 'after-title')
228+
.option('--title <title>', 'TOC title', 'Table of Contents')
229+
.option('--heading-level <level>', 'TOC heading level (1-6)', parseInt, 2)
230+
.option('--marker <marker>', 'Custom marker for TOC replacement (requires --position replace)')
231+
.option('--skip-empty', 'Skip files that don\'t have any headings', true)
232+
.option('-d, --dry-run', 'Show what would be changed without making changes')
233+
.option('-v, --verbose', 'Show detailed output')
234+
.option('--json', 'Output results in JSON format')
235+
.addHelpText(
236+
'after',
237+
`
238+
Examples:
239+
$ markmv toc README.md
240+
$ markmv toc docs/*.md --position after-title --min-depth 2 --max-depth 4
241+
$ markmv toc file.md --position replace --marker "<!-- TOC -->"
242+
$ markmv toc **/*.md --title "Contents" --heading-level 3 --include-line-numbers
243+
244+
Position Options:
245+
top Insert TOC at the very beginning of the file
246+
after-title Insert TOC after the first heading (default)
247+
before-content Insert TOC before main content (after frontmatter)
248+
replace Replace existing TOC using marker or auto-detection
249+
250+
TOC Customization:
251+
--title <title> Custom TOC title (default: "Table of Contents")
252+
--heading-level <level> TOC heading level 1-6 (default: 2, creates ## title)
253+
--marker <marker> Custom marker for replacement (e.g., "<!-- TOC -->")
254+
--min-depth <number> Minimum heading level to include (1-6, default: 1)
255+
--max-depth <number> Maximum heading level to include (1-6, default: 6)
256+
--include-line-numbers Include line numbers in TOC entries`
257+
)
258+
.action(tocCommand);
259+
219260
program
220261
.command('validate')
221262
.description('Find broken links in markdown files')

0 commit comments

Comments
 (0)