Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,38 @@ describe('unwrapMdxCodeBlocks', () => {
</VersionsProvider>
`);
});

it('allow spaces before mdx-code-block info string', () => {
expect(
unwrapMdxCodeBlocks(dedent`
# Title

\`\`\` mdx-code-block
import Comp, {User} from "@site/components/comp"

<Comp prop="test">
<User user={{firstName: "Sébastien"}} />
</Comp>

export const age = 36
\`\`\`

text
`),
).toEqual(dedent`
# Title

import Comp, {User} from "@site/components/comp"

<Comp prop="test">
<User user={{firstName: "Sébastien"}} />
</Comp>

export const age = 36

text
`);
});
});

describe('admonitionTitleToDirectiveLabel', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-utils/src/markdownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
/(?<begin>^|\n)```mdx-code-block\n(?<children>.*?)\n```(?<end>\n|$)/gs;
/(?<begin>^|\n)```(?<spaces>\x20*)mdx-code-block\n(?<children>.*?)\n```(?<end>\n|$)/gs;
const regexp4 =
/(?<begin>^|\n)````mdx-code-block\n(?<children>.*?)\n````(?<end>\n|$)/gs;
/(?<begin>^|\n)````(?<spaces>\x20*)mdx-code-block\n(?<children>.*?)\n````(?<end>\n|$)/gs;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const replacer = (substring: string, ...args: any[]) => {
Expand Down