Skip to content

Commit

Permalink
fix: code block regex (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
kermanx authored Jul 13, 2024
1 parent 8e3bf21 commit 4982e45
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/slidev/node/syntax/transform/code-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MarkdownTransformContext } from '@slidev/types'
import { normalizeRangeStr } from './utils'

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

/**
* Transform code block with wrapper
Expand Down
10 changes: 10 additions & 0 deletions test/__snapshots__/transform-all.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,15 @@ Foo \`{{ code }}\`
</style>
<CodeBlockWrapper v-bind="{}" :ranges='[]'>
\`\`\`ts
function _foo() {
// ...
}
\`\`\`
</CodeBlockWrapper>
</template>"
`;
2 changes: 2 additions & 0 deletions test/transform-all.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Foo \`{{ code }}\`
<style>
.text-green { color: green; }
</style>
<<< ./fixtures/snippets/snippet.ts#snippet
`)

applyMarkdownTransform(ctx)
Expand Down

0 comments on commit 4982e45

Please sign in to comment.