Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Jan 30, 2025
1 parent 163fa70 commit 00f9ce4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
11 changes: 9 additions & 2 deletions packages/slidev/node/syntax/transform/magic-move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ export async function transformMagicMove(ctx: MarkdownTransformContext) {
...ctx.options.utils.shikiOptions,
lang,
}
const { tokens } = await codeToTokens(code, options)
return toKeyedTokens(code, tokens, JSON.stringify([lang, 'themes' in options ? options.themes : options.theme]), lineNumbers)
const { tokens, bg, fg, rootStyle, themeName } = await codeToTokens(code, options)
return {
...toKeyedTokens(code, tokens, JSON.stringify([lang, 'themes' in options ? options.themes : options.theme]), lineNumbers),
bg,
fg,
rootStyle,
themeName,
lang,
}
}))
const compressed = lz.compressToBase64(JSON.stringify(steps))
return `<ShikiMagicMove v-bind="${options}" steps-lz="${compressed}" :step-ranges='${JSON.stringify(ranges)}' />`
Expand Down
3 changes: 2 additions & 1 deletion test/_tutils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { MarkdownTransformContext } from '@slidev/types'
import path from 'node:path'
import MagicString from 'magic-string-stack'
import * as shiki from 'shiki'

export function createTransformContext(code: string, shiki?: any): MarkdownTransformContext {
export function createTransformContext(code: string): MarkdownTransformContext {
const s = new MagicString(code)
return {
s,
Expand Down
14 changes: 2 additions & 12 deletions test/transform-magic-move.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createHighlighter } from 'shiki'
import { expect, it } from 'vitest'
import { transformMagicMove } from '../packages/slidev/node/syntax/transform/magic-move'
import { createTransformContext } from './_tutils'
Expand All @@ -21,12 +20,8 @@ let message = 'Hello, Slidev!'
Some text after
`
const shiki = await createHighlighter({
themes: ['nord'],
langs: ['typescript'],
})

const ctx = createTransformContext(code, shiki)
const ctx = createTransformContext(code)

await transformMagicMove(ctx)

Expand Down Expand Up @@ -61,12 +56,7 @@ console.log('Hello, Angular #2!')
Some text after
`
const shiki = await createHighlighter({
themes: ['nord'],
langs: ['angular-ts'],
})

const ctx = createTransformContext(code, shiki)
const ctx = createTransformContext(code)

await transformMagicMove(ctx)

Expand Down

0 comments on commit 00f9ce4

Please sign in to comment.