From cbbf1a2af43615d20cd6201df25640c6c1968418 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Sat, 18 Jan 2025 19:08:35 +0800 Subject: [PATCH] feat: support async transformers (#60) --- src/core/markdown.ts | 6 +++--- src/types.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/markdown.ts b/src/core/markdown.ts index 141b62a..df1b9be 100644 --- a/src/core/markdown.ts +++ b/src/core/markdown.ts @@ -107,7 +107,7 @@ export function createMarkdown(options: ResolvedOptions) { } = options raw = raw.trimStart() - raw = transforms.before?.(raw, id) ?? raw + raw = await transforms.before?.(raw, id) ?? raw const env: MarkdownEnv = { id } let html = await markdown.renderAsync(raw, env) @@ -138,7 +138,7 @@ export function createMarkdown(options: ResolvedOptions) { html = `<${wrapperComponentName} ${attrs}>${html}` } - html = transforms.after?.(html, id) ?? html + html = await transforms.after?.(html, id) ?? html if (options.escapeCodeTagInterpolation) { // escape curly brackets interpolation in , #14 @@ -194,7 +194,7 @@ export function createMarkdown(options: ResolvedOptions) { scriptLines.push('useHead(head)') } - scriptLines.push(...transforms.extraScripts?.(frontmatter, id) || []) + scriptLines.push(...await transforms.extraScripts?.(frontmatter, id) || []) } if (options.excerpt) { diff --git a/src/types.ts b/src/types.ts index 32c003c..858188c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -187,12 +187,12 @@ export interface Options { * Custom tranformations apply before and after the markdown transformation */ transforms?: { - before?: (code: string, id: string) => string - after?: (code: string, id: string) => string + before?: (code: string, id: string) => string | Promise + after?: (code: string, id: string) => string | Promise /** * Return extra code to be injected into the `