mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Erik Michelson <github@erik.michelson.eu>
21 lines
653 B
TypeScript
21 lines
653 B
TypeScript
import MarkdownIt from 'markdown-it'
|
|
import toc from 'markdown-it-toc-done-right'
|
|
import { TocAst } from '../../../external-types/markdown-it-toc-done-right/interface'
|
|
import { slugify } from '../../editor/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
|
|
})
|
|
}
|