mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 10:17:55 +02:00
fix(markdown): mdx-code-block should support intentation (#10240)
This commit is contained in:
parent
97630b438e
commit
3a0a2a74b8
2 changed files with 32 additions and 2 deletions
|
@ -1229,6 +1229,36 @@ text\r
|
|||
`);
|
||||
});
|
||||
|
||||
it('can unwrap indented mdx code block', () => {
|
||||
expect(
|
||||
unwrapMdxCodeBlocks(dedent`
|
||||
# Title
|
||||
|
||||
<div>
|
||||
\`\`\`mdx-code-block
|
||||
content
|
||||
\`\`\`
|
||||
</div>
|
||||
|
||||
\`\`\`\`mdx-code-block
|
||||
content2
|
||||
\`\`\`\`
|
||||
|
||||
text
|
||||
`),
|
||||
).toEqual(dedent`
|
||||
# Title
|
||||
|
||||
<div>
|
||||
content
|
||||
</div>
|
||||
|
||||
content2
|
||||
|
||||
text
|
||||
`);
|
||||
});
|
||||
|
||||
it('works for realistic example', () => {
|
||||
expect(
|
||||
unwrapMdxCodeBlocks(dedent`
|
||||
|
|
|
@ -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>^|\r?\n)```(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n```(?<end>\r?\n|$)/gs;
|
||||
/(?<begin>^|\r?\n)(?<indentStart>\x20*)```(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n(?<indentEnd>\x20*)```(?<end>\r?\n|$)/gs;
|
||||
const regexp4 =
|
||||
/(?<begin>^|\r?\n)````(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n````(?<end>\r?\n|$)/gs;
|
||||
/(?<begin>^|\r?\n)(?<indentStart>\x20*)````(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n(?<indentEnd>\x20*)````(?<end>\r?\n|$)/gs;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const replacer = (substring: string, ...args: any[]) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue