Files
hedgedoc/markdown-it-plugins/src/toc/toc-options.ts
T
Erik Michelson d16bdecab6 fix(toc): include raw KaTeX from headings in toc
The KaTeX renderer usually renders the raw KaTeX into MathML.
This can not be properly displayed inside the toc and further
makes problems when trying to render a fallback, because then
parts could become duplicated. This commit fixes this by
stripping MathML code completely for the title processing,
leaving the raw KaTeX code intact. The only downside of this
approach is that the surrounding '$' get lost, but this seems
still better than nothing or duplicated content.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-08-02 16:35:12 +02:00

43 lines
1.0 KiB
TypeScript

/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: MIT
*/
import { TocAst } from './toc-ast.js'
export type TocOptions = {
slugify: (name: string, index: number) => string
uniqueSlugStartIndex: number
containerClass: string
containerId: string
listClass: string
itemClass: string
linkClass: string
level: number | number[]
listType: 'ol' | 'ul'
format?: (name: string) => string
callback?: (ast: TocAst) => void
allowedTokenTypes: string[]
}
function defaultSlugify(name: string) {
return encodeURIComponent(String(name).trim().toLowerCase().replace(/\s+/g, '-'))
}
/**
* The default options for the toc plugin.
*/
export const defaultOptions: TocOptions = {
uniqueSlugStartIndex: 0,
containerClass: 'table-of-contents',
containerId: '',
listClass: '',
itemClass: '',
linkClass: '',
level: 1,
listType: 'ol',
allowedTokenTypes: ['text', 'code_inline', 'math', 'inline_math', 'display_math'],
slugify: defaultSlugify,
}