hedgedoc/src/components/markdown-renderer/markdown-it-plugins/document-toc.ts
Tilman Vatteroth 123f959fb3
Move and rename files (2/4) (#987)
Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
2021-02-02 00:03:47 +01:00

26 lines
713 B
TypeScript

/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import MarkdownIt from 'markdown-it'
import toc, { TocAst } from 'markdown-it-toc-done-right'
import { slugify } from '../../editor-page/table-of-contents/table-of-contents'
export type DocumentTocPluginOptions = (ast: TocAst) => void
export const documentToc: MarkdownIt.PluginWithOptions<DocumentTocPluginOptions> = (markdownIt, onToc) => {
if (!onToc) {
return
}
toc(markdownIt, {
placeholder: '(\\[TOC\\]|\\[toc\\])',
listType: 'ul',
level: [1, 2, 3],
callback: (code: string, ast: TocAst): void => {
onToc(ast)
},
slugify: slugify
})
}