Skip to content

Commit 0b34acf

Browse files
committed
fix: add v2 retrocompatible support for quoted admonitions (#9570)
1 parent 1875ca4 commit 0b34acf

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,57 @@ before
13661366
13671367
\t\t:::
13681368
1369+
after
1370+
`);
1371+
});
1372+
1373+
it('transforms directives in quotes', () => {
1374+
expect(
1375+
admonitionTitleToDirectiveLabel(
1376+
`
1377+
before
1378+
1379+
> :::caution There be dragons
1380+
>
1381+
> This is the admonition content
1382+
>
1383+
> :::
1384+
>
1385+
>> :::caution There be dragons
1386+
>>
1387+
>> This is the admonition content
1388+
>>
1389+
>> :::
1390+
> > :::caution There be dragons
1391+
> >
1392+
> > This is the admonition content
1393+
> >
1394+
> > :::
1395+
1396+
after
1397+
`,
1398+
directives,
1399+
),
1400+
).toBe(`
1401+
before
1402+
1403+
> :::caution[There be dragons]
1404+
>
1405+
> This is the admonition content
1406+
>
1407+
> :::
1408+
>
1409+
>> :::caution[There be dragons]
1410+
>>
1411+
>> This is the admonition content
1412+
>>
1413+
>> :::
1414+
> > :::caution[There be dragons]
1415+
> >
1416+
> > This is the admonition content
1417+
> >
1418+
> > :::
1419+
13691420
after
13701421
`);
13711422
});

packages/docusaurus-utils/src/markdownUtils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ export function admonitionTitleToDirectiveLabel(
9797

9898
const directiveNameGroup = `(${admonitionContainerDirectives.join('|')})`;
9999
const regexp = new RegExp(
100-
`^(?<indentation>( +|\t+))?(?<directive>:{3,}${directiveNameGroup}) +(?<title>.*)$`,
100+
`^(?<quote>(> ?)*)(?<indentation>( +|\t+))?(?<directive>:{3,}${directiveNameGroup}) +(?<title>.*)$`,
101101
'gm',
102102
);
103103

104104
return content.replaceAll(regexp, (substring, ...args: any[]) => {
105105
const groups = args.at(-1);
106106

107-
return `${groups.indentation ?? ''}${groups.directive}[${groups.title}]`;
107+
return `${groups.quote ?? ''}${groups.indentation ?? ''}${
108+
groups.directive
109+
}[${groups.title}]`;
108110
});
109111
}
110112

website/_dogfooding/_docs tests/tests/admonitions.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ See admonition title v2 compat syntax bug: https://github.com/facebook/docusauru
7474

7575
:::
7676

77+
## Quoted admonitions
78+
79+
> :::caution There be dragons
80+
>
81+
> This is the admonition content
82+
>
83+
> :::
84+
>
85+
> > :::caution There be dragons
86+
> >
87+
> > This is the admonition content
88+
> >
89+
> > :::
90+
7791
## Official admonitions
7892

7993
Admonitions that are [officially documented](/docs/markdown-features/admonitions)

0 commit comments

Comments
 (0)