@mdit-kdu/plugin-headers v1.0.0
@mdit-kdu/plugin-headers
A markdown-it plugin to get markdown headers.
- Extracts all headers info into markdown-it
env.headers.
Install
npm i @mdit-kdu/plugin-headersUsage
import MarkdownIt from 'markdown-it';
import { headersPlugin } from '@mdit-kdu/plugin-headers';
import type { MarkdownItEnv } from '@mdit-kdu/types';
const md = MarkdownIt({ html: true }).use(headersPlugin, {
// options
});
const env: MarkdownItEnv = {};
const rendered = md.render(
`\
# h1
## h2
### h3
`,
env,
);
console.log(env.headers);Options
format
Type:
(str: string) => stringDetails:
A function for formatting header title.
level
Type:
number[]Default:
[2, 3]Details:
Heading level that going to be extracted.
When using this plugin with markdown-it-anchor (recommended), this option should be a subset of markdown-it-anchor's
leveloption to ensure the header slugs are existed.
shouldAllowNested
Type:
booleanDefault:
falseDetails:
Should allow headers inside nested blocks or not.
If set to
true, headers inside blockquote, list, etc. would also be extracted.
slugify
Type:
(str: string) => stringDefault:
slugifyfrom@mdit-kdu/sharedDetails:
A custom slugification function.
The default slugify function comes from
@mdit-kdu/sharedpackage.When using this plugin with markdown-it-anchor (recommended), this option will be ignored because the
idof the headings have already been determined by markdown-it-anchor'sslugifyoption.
2 years ago