Utility for generating table of contents from markdown content.
This class extracts headings from markdown content and generates formatted table of contents with proper indentation and anchor links.
Basic usage
const generator = new TocGenerator();const content = `# Title\n## Section 1\n### Subsection\n## Section 2`;const result = generator.generateToc(content);console.log(result.toc);// Output:// - [Title](#title)// - [Section 1](#section-1)// - [Subsection](#subsection)// - [Section 2](#section-2) Copy
const generator = new TocGenerator();const content = `# Title\n## Section 1\n### Subsection\n## Section 2`;const result = generator.generateToc(content);console.log(result.toc);// Output:// - [Title](#title)// - [Section 1](#section-1)// - [Subsection](#subsection)// - [Section 2](#section-2)
With custom options
const generator = new TocGenerator();const options = {minDepth: 2,maxDepth: 4,includeLineNumbers: true};const result = generator.generateToc(content, options); Copy
const generator = new TocGenerator();const options = {minDepth: 2,maxDepth: 4,includeLineNumbers: true};const result = generator.generateToc(content, options);
Generate table of contents from markdown content.
Markdown content to analyze
Configuration options
TOC result
Extract headings from markdown content without generating TOC.
Array of headings
Utility for generating table of contents from markdown content.
This class extracts headings from markdown content and generates formatted table of contents with proper indentation and anchor links.
Example
Basic usage
Example
With custom options