mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 07:34:42 -04: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 {
|
export class TableOfContentsMarkdownExtension extends EventMarkdownRendererExtension {
|
||||||
public static readonly EVENT_NAME = 'TocChange'
|
public static readonly EVENT_NAME = 'TocChange'
|
||||||
private lastAst: TocAst | undefined = undefined
|
private lastAst: TocAst | undefined = undefined
|
||||||
|
private postAst = false
|
||||||
|
|
||||||
public configureMarkdownIt(markdownIt: MarkdownIt): void {
|
public configureMarkdownIt(markdownIt: MarkdownIt): void {
|
||||||
const eventEmitter = this.eventEmitter
|
toc(markdownIt, {
|
||||||
if (eventEmitter !== undefined) {
|
listType: 'ul',
|
||||||
toc(markdownIt, {
|
level: [1, 2, 3],
|
||||||
listType: 'ul',
|
callback: (ast: TocAst): void => {
|
||||||
level: [1, 2, 3],
|
if (equal(ast, this.lastAst)) {
|
||||||
callback: (ast: TocAst): void => {
|
return
|
||||||
if (equal(ast, this.lastAst)) {
|
}
|
||||||
return
|
this.lastAst = ast
|
||||||
}
|
this.postAst = true
|
||||||
this.lastAst = ast
|
},
|
||||||
eventEmitter.emit(TableOfContentsMarkdownExtension.EVENT_NAME, ast)
|
slugify: tocSlugify
|
||||||
},
|
})
|
||||||
slugify: tocSlugify
|
}
|
||||||
})
|
|
||||||
|
public doAfterRendering(): void {
|
||||||
|
if (!this.postAst) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
this.postAst = false
|
||||||
|
this.eventEmitter.emit(TableOfContentsMarkdownExtension.EVENT_NAME, this.lastAst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue