diff --git a/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts b/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
index 0e04dbf5c280..734baea200bd 100644
--- a/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
+++ b/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
@@ -1251,6 +1251,38 @@ describe('unwrapMdxCodeBlocks', () => {
`);
});
+
+ it('allow spaces before mdx-code-block info string', () => {
+ expect(
+ unwrapMdxCodeBlocks(dedent`
+ # Title
+
+ \`\`\` mdx-code-block
+ import Comp, {User} from "@site/components/comp"
+
+
+
+
+
+ export const age = 36
+ \`\`\`
+
+ text
+ `),
+ ).toEqual(dedent`
+ # Title
+
+ import Comp, {User} from "@site/components/comp"
+
+
+
+
+
+ export const age = 36
+
+ text
+ `);
+ });
});
describe('admonitionTitleToDirectiveLabel', () => {
diff --git a/packages/docusaurus-utils/src/markdownUtils.ts b/packages/docusaurus-utils/src/markdownUtils.ts
index 87aac88f09b1..ce0766de6ce2 100644
--- a/packages/docusaurus-utils/src/markdownUtils.ts
+++ b/packages/docusaurus-utils/src/markdownUtils.ts
@@ -70,9 +70,9 @@ export function escapeMarkdownHeadingIds(content: string): string {
export function unwrapMdxCodeBlocks(content: string): string {
// We only support 3/4 backticks on purpose, should be good enough
const regexp3 =
- /(?^|\n)```mdx-code-block\n(?.*?)\n```(?\n|$)/gs;
+ /(?^|\n)```(?\x20*)mdx-code-block\n(?.*?)\n```(?\n|$)/gs;
const regexp4 =
- /(?^|\n)````mdx-code-block\n(?.*?)\n````(?\n|$)/gs;
+ /(?^|\n)````(?\x20*)mdx-code-block\n(?.*?)\n````(?\n|$)/gs;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const replacer = (substring: string, ...args: any[]) => {