Skip to content

Commit 4982e45

Browse files
authored
fix: code block regex (#1755)
1 parent 8e3bf21 commit 4982e45

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

packages/slidev/node/syntax/transform/code-wrapper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { MarkdownTransformContext } from '@slidev/types'
22
import { normalizeRangeStr } from './utils'
33

44
// eslint-disable-next-line regexp/no-super-linear-backtracking
5-
export const reCodeBlock = /^```([\w'-]+)(?:\s*\{([\w*,|-]+)\}\s*?(\{[^}]*\})?([^\r\n]*))?\r?\n(\S[\s\S]*?)^```$/gm
5+
export const reCodeBlock = /^```([\w'-]+)?\s*(?:\{([\w*,|-]+)\}\s*?(\{[^}]*\})?([^\r\n]*))?\r?\n(\S[\s\S]*?)^```$/gm
66

77
/**
88
* Transform code block with wrapper

test/__snapshots__/transform-all.test.ts.snap

+10
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,15 @@ Foo \`{{ code }}\`
4747
</style>
4848
4949
50+
<CodeBlockWrapper v-bind="{}" :ranges='[]'>
51+
52+
\`\`\`ts
53+
function _foo() {
54+
// ...
55+
}
56+
\`\`\`
57+
58+
</CodeBlockWrapper>
59+
5060
</template>"
5161
`;

test/transform-all.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Foo \`{{ code }}\`
2626
<style>
2727
.text-green { color: green; }
2828
</style>
29+
30+
<<< ./fixtures/snippets/snippet.ts#snippet
2931
`)
3032

3133
applyMarkdownTransform(ctx)

0 commit comments

Comments
 (0)