mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
fix(toc): post toc after rendering instead of during
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
b04b5cc3e1
commit
b0c3ed9f8b
1 changed files with 20 additions and 14 deletions
|
@ -16,22 +16,28 @@ import type MarkdownIt from 'markdown-it'
|
|||
export class TableOfContentsMarkdownExtension extends EventMarkdownRendererExtension {
|
||||
public static readonly EVENT_NAME = 'TocChange'
|
||||
private lastAst: TocAst | undefined = undefined
|
||||
private postAst = false
|
||||
|
||||
public configureMarkdownIt(markdownIt: MarkdownIt): void {
|
||||
const eventEmitter = this.eventEmitter
|
||||
if (eventEmitter !== undefined) {
|
||||
toc(markdownIt, {
|
||||
listType: 'ul',
|
||||
level: [1, 2, 3],
|
||||
callback: (ast: TocAst): void => {
|
||||
if (equal(ast, this.lastAst)) {
|
||||
return
|
||||
}
|
||||
this.lastAst = ast
|
||||
eventEmitter.emit(TableOfContentsMarkdownExtension.EVENT_NAME, ast)
|
||||
},
|
||||
slugify: tocSlugify
|
||||
})
|
||||
toc(markdownIt, {
|
||||
listType: 'ul',
|
||||
level: [1, 2, 3],
|
||||
callback: (ast: TocAst): void => {
|
||||
if (equal(ast, this.lastAst)) {
|
||||
return
|
||||
}
|
||||
this.lastAst = ast
|
||||
this.postAst = true
|
||||
},
|
||||
slugify: tocSlugify
|
||||
})
|
||||
}
|
||||
|
||||
public doAfterRendering(): void {
|
||||
if (!this.postAst) {
|
||||
return
|
||||
}
|
||||
this.postAst = false
|
||||
this.eventEmitter.emit(TableOfContentsMarkdownExtension.EVENT_NAME, this.lastAst)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue