From c07caeb30da6b0477b0ea3dcc4912d24a648e706 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Mon, 22 Jan 2024 04:26:15 +0000 Subject: [PATCH 1/2] fix: allow spaces before `mdx-code-block` --- packages/docusaurus-utils/src/markdownUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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[]) => { From 697afd055ecfb6d9719c6a4162ee7e367f7b5f10 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Mon, 22 Jan 2024 04:27:59 +0000 Subject: [PATCH 2/2] test: add test --- .../src/__tests__/markdownUtils.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) 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', () => {