Skip to content

Commit d69e353

Browse files
s-lightantfu
andauthored
feat: add rendererRenderAsync (#4)
Co-authored-by: Anthony Fu <[email protected]>
1 parent 3f4af75 commit d69e353

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function randStr(): string {
3939
}
4040

4141
export type MarkdownItAsyncPlaceholderMap = Map<string, [promise: Promise<string>, str: string, lang: string, attrs: string]>
42+
export type Token = ReturnType<MarkdownIt['parse']>[number]
4243

4344
export class MarkdownItAsync extends MarkdownIt {
4445
placeholderMap: MarkdownItAsyncPlaceholderMap
@@ -74,9 +75,18 @@ export class MarkdownItAsync extends MarkdownIt {
7475
}
7576

7677
async renderAsync(src: string, env?: any): Promise<string> {
78+
return this.rendererRenderAsync(
79+
this.parse(src, env),
80+
this.options,
81+
env,
82+
)
83+
}
84+
85+
async rendererRenderAsync(tokens: Token[], options: Options, env: any): Promise<string> {
7786
this.options.highlight = wrapHightlight(this.options.highlight, this.placeholderMap)
7887
this.disableWarn = true
79-
const result = this.render(src, env)
88+
const result = this.renderer.render(tokens, options, env)
89+
8090
this.disableWarn = false
8191
return replaceAsync(result, placeholderRe, async (match, id) => {
8292
if (!this.placeholderMap.has(id))

0 commit comments

Comments
 (0)