Skip to content

Commit 4dc5764

Browse files
committed
Fix JSX expression regex to handle nested braces
Replace simple regex pattern that failed on nested braces with existing BRACE_PATTERN that properly handles up to 3 levels of nesting. This fixes issues with expressions like {obj || {default: true}} and {items.map(x => ({a: x}))} where stray closing braces would remain in the output.
1 parent 2055fee commit 4dc5764

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

app/api/markdown/[[...slug]]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const JSX_WITH_CHILDREN_REGEX = new RegExp(
3535
"g"
3636
);
3737
const CODE_BLOCK_REGEX = /```[\s\S]*?```/g;
38-
const JSX_EXPRESSION_REGEX = /\{[^}]+\}/g;
38+
const JSX_EXPRESSION_REGEX = new RegExp(BRACE_PATTERN, "g");
3939
const EXCESSIVE_NEWLINES_REGEX = /\n{3,}/g;
4040
const CODE_BLOCK_PLACEHOLDER_REGEX = /__CODE_BLOCK_(\d+)__/g;
4141

0 commit comments

Comments
 (0)