Generate a markdown TOC (table of contents) with Remarkable
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Command-line tool for processing markdown files and generating table of contents with support for file modification, custom formatting, and JSON output.
The CLI provides a simple interface for TOC generation from files or stdin.
# Generate TOC and print to stdout
markdown-toc <input-file>
# Read from stdin
echo "# Title\n## Section" | markdown-toc -
# Generate TOC and inject into file
markdown-toc -i <input-file>Usage Examples:
# Basic TOC generation
markdown-toc README.md
# Process from stdin
cat document.md | markdown-toc -
# Inject TOC into file between <!-- toc --> markers
markdown-toc -i README.mdComprehensive options for customizing CLI behavior.
markdown-toc [options] <input>
Options:
-i Edit the input file directly, injecting TOC at <!-- toc -->
--json Print the TOC in JSON format
--append <string> Append a string to the end of the TOC
--bullets <chars> Bullets to use for items in the generated TOC
--maxdepth <number> Use headings whose depth is at most maxdepth (default: 6)
--no-firsth1 Include the first h1-level heading in a file
--no-stripHeadingTags Do not strip extraneous HTML tags from heading text
Arguments:
<input> The Markdown file to parse for TOC, or "-" for stdinUsage Examples with Options:
# Limit depth and customize bullets
markdown-toc --maxdepth 3 --bullets "*" README.md
# Multiple bullet types for different levels
markdown-toc --bullets "*" --bullets "-" --bullets "+" README.md
# Include first H1 and append footer
markdown-toc --no-firsth1 --append "_(Generated by markdown-toc)_" README.md
# Output JSON format
markdown-toc --json README.md
# Combine multiple options
markdown-toc -i --maxdepth 2 --bullets "-" --append "\n\n*Auto-generated*" docs/API.mdIn-place file modification with the -i flag.
# Before: README.md contains <!-- toc --> marker
markdown-toc -i README.md
# After: README.md has TOC injected at marker location
# Process multiple files (using shell globbing)
for file in docs/*.md; do
markdown-toc -i --maxdepth 3 "$file"
doneStructured JSON output for programmatic use.
markdown-toc --json README.md[
{
"content": "Introduction",
"slug": "introduction",
"lvl": 1,
"i": 0,
"seen": 0
},
{
"content": "Getting Started",
"slug": "getting-started",
"lvl": 2,
"i": 1,
"seen": 0
}
]Process markdown content from stdin for pipeline usage.
# Generate TOC from stdin
echo -e "# Title\n## Section\n### Subsection" | markdown-toc -
# Pipeline processing
curl -s https://raw.githubusercontent.com/user/repo/main/README.md | markdown-toc -
# Process with options
cat document.md | markdown-toc --maxdepth 2 --bullets "•" -The CLI includes comprehensive error handling and validation.
# Invalid usage examples that trigger errors:
# Missing input file
markdown-toc
# Error: Usage: markdown-toc [options] <input>
# Using -i with stdin
echo "# Title" | markdown-toc -i -
# Error: markdown-toc: you cannot use -i with "-" (stdin) for input
# Using -i with --json
markdown-toc -i --json README.md
# Error: markdown-toc: you cannot use both --json and -i
# File not found
markdown-toc nonexistent.md
# Error: ENOENT: no such file or directoryCommon integration patterns for build processes and automation.
# In package.json scripts
{
"scripts": {
"docs:toc": "markdown-toc -i README.md",
"docs:build": "markdown-toc -i --maxdepth 3 docs/*.md"
}
}
# In Makefile
docs-toc:
find docs -name "*.md" -exec markdown-toc -i --maxdepth 2 {} \;
# In CI/CD pipeline
script:
- markdown-toc --json README.md > toc.json
- markdown-toc -i --maxdepth 3 --append "_(Updated: $(date))_" docs/API.mdProcess multiple files with consistent options.
# Process all markdown files in directory
find . -name "*.md" -not -path "./node_modules/*" | \
xargs -I {} markdown-toc -i --maxdepth 3 --bullets "-" {}
# Generate TOC for all files and save outputs
for file in docs/*.md; do
basename=$(basename "$file" .md)
markdown-toc "$file" > "toc-${basename}.md"
doneComplex processing scenarios combining options.
# Generate detailed TOC with custom formatting
markdown-toc \
--maxdepth 4 \
--bullets "▶" \
--append "\n\n---\n*Table of contents generated on $(date)*" \
--no-stripHeadingTags \
documentation.md
# Process with custom bullets for each level
markdown-toc \
--bullets "•" \
--bullets "◦" \
--bullets "▪" \
--bullets "▫" \
complex-document.mdThe CLI uses standard exit codes for error handling.
# Success
markdown-toc README.md
echo $? # Output: 0
# File not found
markdown-toc missing.md
echo $? # Output: 1
# Invalid arguments
markdown-toc -i --json README.md
echo $? # Output: 1