Skip to content

Commit 7d16032

Browse files
committed
fix: compatible with plugins that replaces md.render
1 parent bc451be commit 7d16032

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type MarkdownItAsyncPlaceholderMap = Map<string, [promise: Promise<string
4242

4343
export class MarkdownItAsync extends MarkdownIt {
4444
placeholderMap: MarkdownItAsyncPlaceholderMap
45+
private disableWarn = false
4546

4647
constructor(presetName: PresetName, options?: MarkdownItAsyncOptions)
4748
constructor(options?: MarkdownItAsyncOptions)
@@ -66,15 +67,17 @@ export class MarkdownItAsync extends MarkdownIt {
6667
}
6768

6869
render(src: string, env?: any): string {
69-
if ((this.options as MarkdownItAsyncOptions).warnOnSyncRender) {
70+
if ((this.options as MarkdownItAsyncOptions).warnOnSyncRender && !this.disableWarn) {
7071
console.warn('[markdown-it-async] Please use `md.renderAsync` instead of `md.render`')
7172
}
7273
return super.render(src, env)
7374
}
7475

7576
async renderAsync(src: string, env?: any): Promise<string> {
7677
this.options.highlight = wrapHightlight(this.options.highlight, this.placeholderMap)
77-
const result = super.render(src, env)
78+
this.disableWarn = true
79+
const result = this.render(src, env)
80+
this.disableWarn = false
7881
return replaceAsync(result, placeholderRe, async (match, id) => {
7982
if (!this.placeholderMap.has(id))
8083
throw new Error(`Unknown highlight placeholder id: ${id}`)

0 commit comments

Comments
 (0)