Skip to content

Commit

Permalink
fix: support {at:x} for magic move
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 4, 2024
1 parent e18cddf commit 14041b4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion demo/starter/slides.md
Expand Up @@ -190,7 +190,7 @@ Powered by [shiki-magic-move](https://shiki-magic-move.netlify.app/), Slidev sup

Add multiple code blocks and wrap them with <code>````md magic-move</code> (four backticks) to enable the magic move. For example:

````md magic-move
````md magic-move {at:0}
```ts
const author = reactive({
name: 'John Doe',
Expand Down Expand Up @@ -234,6 +234,8 @@ export default {
}
```

Non-code blocks are ignored.

```vue
<script setup>
const author = {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/builtin/ShikiMagicMove.vue
Expand Up @@ -26,7 +26,7 @@ onMounted(() => {
if (!clicks || clicks.disabled)
return
const { start, end, delta } = clicks.resolve(props.at || '+1', steps.length - 1)
const { start, end, delta } = clicks.resolve(props.at ?? '+1', steps.length - 1)
clicks.register(id, { max: end, delta })
watchEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/slidev/node/plugins/markdown.ts
Expand Up @@ -238,7 +238,7 @@ export function transformSlotSugar(md: string) {
return lines.join('\n')
}

const reMagicMoveBlock = /^````(?:md|markdown) magic-move(?:[ ]*?({.*?})?([^\n]*?))?\n([\s\S]+?)^````$/mg
const reMagicMoveBlock = /^````(?:md|markdown) magic-move(?:[ ]*(\{.*?\})?([^\n]*?))?\n([\s\S]+?)^````$/mg
const reCodeBlock = /^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?(.*?))?\n([\s\S]+?)^```$/mg

/**
Expand All @@ -251,7 +251,7 @@ export function transformMagicMove(
) {
return md.replace(
reMagicMoveBlock,
(full, _options = '', _attrs = '', body: string) => {
(full, options = '{}', _attrs = '', body: string) => {
if (!shiki || !shikiOptions)
throw new Error('Shiki is required for Magic Move. You may need to set `highlighter: shiki` in your Slidev config.')

Expand All @@ -267,7 +267,7 @@ export function transformMagicMove(
}),
)
const compressed = lz.compressToBase64(JSON.stringify(steps))
return `<ShikiMagicMove steps-lz="${compressed}" />`
return `<ShikiMagicMove v-bind="${options}" steps-lz="${compressed}" />`
},
)
}
Expand Down

0 comments on commit 14041b4

Please sign in to comment.