8000 feat: support async transformers by kermanx · Pull Request #60 · unplugin/unplugin-vue-markdown · GitHub
[go: up one dir, main page]

Skip to content

feat: support async transformers #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2025
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
0