Skip to content

Commit cbbf1a2

Browse files
authored
feat: support async transformers (#60)
1 parent 13160d1 commit cbbf1a2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/core/markdown.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function createMarkdown(options: ResolvedOptions) {
107107
} = options
108108

109109
raw = raw.trimStart()
110-
raw = transforms.before?.(raw, id) ?? raw
110+
raw = await transforms.before?.(raw, id) ?? raw
111111

112112
const env: MarkdownEnv = { id }
113113
let html = await markdown.renderAsync(raw, env)
@@ -138,7 +138,7 @@ export function createMarkdown(options: ResolvedOptions) {
138138
html = `<${wrapperComponentName} ${attrs}>${html}</${wrapperComponentName}>`
139139
}
140140

141-
html = transforms.after?.(html, id) ?? html
141+
html = await transforms.after?.(html, id) ?? html
142142

143143
if (options.escapeCodeTagInterpolation) {
144144
// escape curly brackets interpolation in <code>, #14
@@ -194,7 +194,7 @@ export function createMarkdown(options: ResolvedOptions) {
194194
scriptLines.push('useHead(head)')
195195
}
196196

197-
scriptLines.push(...transforms.extraScripts?.(frontmatter, id) || [])
197+
scriptLines.push(...await transforms.extraScripts?.(frontmatter, id) || [])
198198
}
199199

200200
if (options.excerpt) {

src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ export interface Options {
187187
* Custom tranformations apply before and after the markdown transformation
188188
*/
189189
transforms?: {
190-
before?: (code: string, id: string) => string
191-
after?: (code: string, id: string) => string
190+
before?: (code: string, id: string) => string | Promise<string>
191+
after?: (code: string, id: string) => string | Promise<string>
192192
/**
193193
* Return extra code to be injected into the `<script>` tag
194194
*/
195-
extraScripts?: (frontmatter: Record<string, any>, id: string) => string[]
195+
extraScripts?: (frontmatter: Record<string, any>, id: string) => string[] | Promise<string[]>
196196
}
197197

198198
include?: FilterPattern

0 commit comments

Comments
 (0)