File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
packages/docusaurus-utils/src Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -1229,6 +1229,36 @@ text\r
1229
1229
` ) ;
1230
1230
} ) ;
1231
1231
1232
+ it ( 'can unwrap indented mdx code block' , ( ) => {
1233
+ expect (
1234
+ unwrapMdxCodeBlocks ( dedent `
1235
+ # Title
1236
+
1237
+ <div>
1238
+ \`\`\`mdx-code-block
1239
+ content
1240
+ \`\`\`
1241
+ </div>
1242
+
1243
+ \`\`\`\`mdx-code-block
1244
+ content2
1245
+ \`\`\`\`
1246
+
1247
+ text
1248
+ ` ) ,
1249
+ ) . toEqual ( dedent `
1250
+ # Title
1251
+
1252
+ <div>
1253
+ content
1254
+ </div>
1255
+
1256
+ content2
1257
+
1258
+ text
1259
+ ` ) ;
1260
+ } ) ;
1261
+
1232
1262
it ( 'works for realistic example' , ( ) => {
1233
1263
expect (
1234
1264
unwrapMdxCodeBlocks ( dedent `
Original file line number Diff line number Diff line change @@ -70,9 +70,9 @@ export function escapeMarkdownHeadingIds(content: string): string {
70
70
export function unwrapMdxCodeBlocks ( content : string ) : string {
71
71
// We only support 3/4 backticks on purpose, should be good enough
72
72
const regexp3 =
73
- / (?< begin > ^ | \r ? \n ) ` ` ` (?< spaces > \x20 * ) m d x - c o d e - b l o c k \r ? \n (?< children > .* ?) \r ? \n ` ` ` (?< end > \r ? \n | $ ) / gs;
73
+ / (?< begin > ^ | \r ? \n ) (?< indentStart > \x20 * ) ` ` ` (?< spaces > \x20 * ) m d x - c o d e - b l o c k \r ? \n (?< children > .* ?) \r ? \n (?< indentEnd > \x20 * ) ` ` ` (?< end > \r ? \n | $ ) / gs;
74
74
const regexp4 =
75
- / (?< begin > ^ | \r ? \n ) ` ` ` ` (?< spaces > \x20 * ) m d x - c o d e - b l o c k \r ? \n (?< children > .* ?) \r ? \n ` ` ` ` (?< end > \r ? \n | $ ) / gs;
75
+ / (?< begin > ^ | \r ? \n ) (?< indentStart > \x20 * ) ` ` ` ` (?< spaces > \x20 * ) m d x - c o d e - b l o c k \r ? \n (?< children > .* ?) \r ? \n (?< indentEnd > \x20 * ) ` ` ` ` (?< end > \r ? \n | $ ) / gs;
76
76
77
77
// eslint-disable-next-line @typescript-eslint/no-explicit-any
78
78
const replacer = ( substring : string , ...args : any [ ] ) => {
You can’t perform that action at this time.
0 commit comments