Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -138,7 +138,7 @@ export function createMarkdown(options: ResolvedOptions) {
html = `<${wrapperComponentName} ${attrs}>${html}</${wrapperComponentName}>`
}

html = transforms.after?.(html, id) ?? html
html = await transforms.after?.(html, id) ?? html

if (options.escapeCodeTagInterpolation) {
// escape curly brackets interpolation in <code>, #14
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
after?: (code: string, id: string) => string | Promise<string>
/**
* Return extra code to be injected into the `<script>` tag
*/
extraScripts?: (frontmatter: Record<string, any>, id: string) => string[]
extraScripts?: (frontmatter: Record<string, any>, id: string) => string[] | Promise<string[]>
}

include?: FilterPattern
Expand Down
Loading