Skip to content

Commit

Permalink
feat: support async markdown transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
kermanx committed Jan 18, 2025
1 parent a100ae6 commit 1862cf3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions packages/slidev/node/vite/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export async function createMarkdownPlugin(
},
transforms: {
...mdOptions?.transforms,
before(code, id) {
async before(code, id) {
// Skip entry Markdown files
if (options.data.markdownFiles[id])
return ''

code = mdOptions?.transforms?.before?.(code, id) ?? code
code = await mdOptions?.transforms?.before?.(code, id) ?? code

const match = id.match(regexSlideSourceId)
if (!match)
Expand All @@ -55,7 +55,7 @@ export async function createMarkdownPlugin(
for (const transformer of transformers) {
if (!transformer)
continue
transformer(ctx)
await transformer(ctx)
if (!ctx.s.isEmpty())
ctx.s.commit()
}
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Awaitable } from '@antfu/utils'
import type MagicString from 'magic-string-stack'
import type { ResolvedSlidevOptions } from './options'
import type { SlideInfo } from './types'
Expand All @@ -19,4 +20,4 @@ export interface MarkdownTransformContext {
options: ResolvedSlidevOptions
}

export type MarkdownTransformer = (ctx: MarkdownTransformContext) => void
export type MarkdownTransformer = (ctx: MarkdownTransformContext) => Awaitable<void>
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ catalog:
unocss: ^65.4.0
unplugin-icons: ^22.0.0
unplugin-vue-components: ^28.0.0
unplugin-vue-markdown: ^28.0.0
unplugin-vue-markdown: ^28.1.0
untun: ^0.1.3
uqr: ^0.1.2
vite: ^6.0.7
Expand Down

0 comments on commit 1862cf3

Please sign in to comment.