Guides
Table of Contents
Nizel collects headings into result.toc when toc: true is set.
Enable TOC
const nizel = useNizel({ toc: true });
const { toc } = await nizel(`
# Title
## Section 1
### Subsection
## Section 2
`);
Output Format
The toc array contains objects with:
interface TocEntry {
level: number; // heading level (1-6)
text: string; // heading text content
slug: string; // generated anchor slug
}
Example
// Given:
// # Getting Started
// ## Install
// ## Configuration
// ### Theme
// ### Language
const { toc } = await nizel(markdown, { toc: true });
// toc === [
// { level: 1, text: 'Getting Started', slug: 'getting-started' },
// { level: 2, text: 'Install', slug: 'install' },
// { level: 2, text: 'Configuration', slug: 'configuration' },
// { level: 3, text: 'Theme', slug: 'theme' },
// { level: 3, text: 'Language', slug: 'language' },
// ]
Heading Anchors
When anchors: true, Nizel adds id attributes to headings matching their slug:
<h1 id="getting-started">Getting Started</h1>
<h2 id="install">Install</h2>
Slug Generation
Slugs follow GitHub-style slugification by default:
- lowercase
- spaces become hyphens
- special characters removed
- consecutive hyphens collapsed
Use slugStyle: 'classic' for a simpler algorithm.