@mdit-kdu/plugin-headers
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@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-headers

Usage

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) => string

  • Details:

    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 level option to ensure the header slugs are existed.

shouldAllowNested

  • Type: boolean

  • Default: false

  • Details:

    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) => string

  • Default: slugify from @mdit-kdu/shared

  • Details:

    A custom slugification function.

    The default slugify function comes from @mdit-kdu/shared package.

    When using this plugin with markdown-it-anchor (recommended), this option will be ignored because the id of the headings have already been determined by markdown-it-anchor's slugify option.

Package Sidebar

Install

npm i @mdit-kdu/plugin-headers

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

9.39 kB

Total Files

8

Last publish

Collaborators

  • nkduy