Skip to content

Commit 1862cf3

Browse files
committed
feat: support async markdown transformer
1 parent a100ae6 commit 1862cf3

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

packages/slidev/node/vite/markdown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ export async function createMarkdownPlugin(
3333
},
3434
transforms: {
3535
...mdOptions?.transforms,
36-
before(code, id) {
36+
async before(code, id) {
3737
// Skip entry Markdown files
3838
if (options.data.markdownFiles[id])
3939
return ''
4040

41-
code = mdOptions?.transforms?.before?.(code, id) ?? code
41+
code = await mdOptions?.transforms?.before?.(code, id) ?? code
4242

4343
const match = id.match(regexSlideSourceId)
4444
if (!match)
@@ -55,7 +55,7 @@ export async function createMarkdownPlugin(
5555
for (const transformer of transformers) {
5656
if (!transformer)
5757
continue
58-
transformer(ctx)
58+
await transformer(ctx)
5959
if (!ctx.s.isEmpty())
6060
ctx.s.commit()
6161
}

packages/types/src/transform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Awaitable } from '@antfu/utils'
12
import type MagicString from 'magic-string-stack'
23
import type { ResolvedSlidevOptions } from './options'
34
import type { SlideInfo } from './types'
@@ -19,4 +20,4 @@ export interface MarkdownTransformContext {
1920
options: ResolvedSlidevOptions
2021
}
2122

22-
export type MarkdownTransformer = (ctx: MarkdownTransformContext) => void
23+
export type MarkdownTransformer = (ctx: MarkdownTransformContext) => Awaitable<void>

pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ catalog:
122122
unocss: ^65.4.0
123123
unplugin-icons: ^22.0.0
124124
unplugin-vue-components: ^28.0.0
125-
unplugin-vue-markdown: ^28.0.0
125+
unplugin-vue-markdown: ^28.1.0
126126
untun: ^0.1.3
127127
uqr: ^0.1.2
128128
vite: ^6.0.7

0 commit comments

Comments
 (0)