diff --git a/packages/slidev/node/plugins/markdown.ts b/packages/slidev/node/plugins/markdown.ts index e68c58b125..4faa354705 100644 --- a/packages/slidev/node/plugins/markdown.ts +++ b/packages/slidev/node/plugins/markdown.ts @@ -247,7 +247,7 @@ export function transformSlotSugar(md: string) { } const reMagicMoveBlock = /^````(?:md|markdown) magic-move(?:[ ]*(\{.*?\})?([^\n]*?))?\n([\s\S]+?)^````$/mg -const reCodeBlock = /^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?(.*?))?\n([\s\S]+?)^```$/mg +const reCodeBlock = /^```([\w'-]+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?(.*?))?\n([\s\S]+?)^```$/mg /** * Transform magic-move code blocks diff --git a/test/transform-magic-move.test.ts b/test/transform-magic-move.test.ts index 6f87fba21f..fbcf7b4ae8 100644 --- a/test/transform-magic-move.test.ts +++ b/test/transform-magic-move.test.ts @@ -46,3 +46,45 @@ Some text after " `) }) + +it('hyphenated code language', async () => { + const code = ` + +Some text before + +\`\`\`\`md magic-move +\`\`\`angular-ts +console.log('Hello, Angular!') +\`\`\` +\`\`\`angular-ts +console.log('Hello, Angular #2!') +\`\`\` +\`\`\`\` + +Some text after + +` + const shiki = await getHighlighter({ + themes: ['nord'], + langs: ['angular-ts'], + }) + + expect(transformMagicMove( + code, + shiki, + { + theme: 'nord', + }, + )) + .toMatchInlineSnapshot(` + " + + Some text before + + + + Some text after + + " + `) +})