2020-11-22 15:50:07 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2020 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2020-10-08 16:24:42 -04:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|