mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 20:27:20 +02:00
fix: add v2 retrocompatible support for quoted admonitions (#9570)
This commit is contained in:
parent
2c0bf8a3d8
commit
7c32fc341f
3 changed files with 69 additions and 2 deletions
|
@ -1366,6 +1366,57 @@ before
|
||||||
|
|
||||||
\t\t:::
|
\t\t:::
|
||||||
|
|
||||||
|
after
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('transforms directives in quotes', () => {
|
||||||
|
expect(
|
||||||
|
admonitionTitleToDirectiveLabel(
|
||||||
|
`
|
||||||
|
before
|
||||||
|
|
||||||
|
> :::caution There be dragons
|
||||||
|
>
|
||||||
|
> This is the admonition content
|
||||||
|
>
|
||||||
|
> :::
|
||||||
|
>
|
||||||
|
>> :::caution There be dragons
|
||||||
|
>>
|
||||||
|
>> This is the admonition content
|
||||||
|
>>
|
||||||
|
>> :::
|
||||||
|
> > :::caution There be dragons
|
||||||
|
> >
|
||||||
|
> > This is the admonition content
|
||||||
|
> >
|
||||||
|
> > :::
|
||||||
|
|
||||||
|
after
|
||||||
|
`,
|
||||||
|
directives,
|
||||||
|
),
|
||||||
|
).toBe(`
|
||||||
|
before
|
||||||
|
|
||||||
|
> :::caution[There be dragons]
|
||||||
|
>
|
||||||
|
> This is the admonition content
|
||||||
|
>
|
||||||
|
> :::
|
||||||
|
>
|
||||||
|
>> :::caution[There be dragons]
|
||||||
|
>>
|
||||||
|
>> This is the admonition content
|
||||||
|
>>
|
||||||
|
>> :::
|
||||||
|
> > :::caution[There be dragons]
|
||||||
|
> >
|
||||||
|
> > This is the admonition content
|
||||||
|
> >
|
||||||
|
> > :::
|
||||||
|
|
||||||
after
|
after
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -97,14 +97,16 @@ export function admonitionTitleToDirectiveLabel(
|
||||||
|
|
||||||
const directiveNameGroup = `(${admonitionContainerDirectives.join('|')})`;
|
const directiveNameGroup = `(${admonitionContainerDirectives.join('|')})`;
|
||||||
const regexp = new RegExp(
|
const regexp = new RegExp(
|
||||||
`^(?<indentation>( +|\t+))?(?<directive>:{3,}${directiveNameGroup}) +(?<title>.*)$`,
|
`^(?<quote>(> ?)*)(?<indentation>( +|\t+))?(?<directive>:{3,}${directiveNameGroup}) +(?<title>.*)$`,
|
||||||
'gm',
|
'gm',
|
||||||
);
|
);
|
||||||
|
|
||||||
return content.replaceAll(regexp, (substring, ...args: any[]) => {
|
return content.replaceAll(regexp, (substring, ...args: any[]) => {
|
||||||
const groups = args.at(-1);
|
const groups = args.at(-1);
|
||||||
|
|
||||||
return `${groups.indentation ?? ''}${groups.directive}[${groups.title}]`;
|
return `${groups.quote ?? ''}${groups.indentation ?? ''}${
|
||||||
|
groups.directive
|
||||||
|
}[${groups.title}]`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,20 @@ See admonition title v2 compat syntax bug: https://github.com/facebook/docusauru
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
## Quoted admonitions
|
||||||
|
|
||||||
|
> :::caution There be dragons
|
||||||
|
>
|
||||||
|
> This is the admonition content
|
||||||
|
>
|
||||||
|
> :::
|
||||||
|
>
|
||||||
|
> > :::caution There be dragons
|
||||||
|
> >
|
||||||
|
> > This is the admonition content
|
||||||
|
> >
|
||||||
|
> > :::
|
||||||
|
|
||||||
## Official admonitions
|
## Official admonitions
|
||||||
|
|
||||||
Admonitions that are [officially documented](/docs/markdown-features/admonitions)
|
Admonitions that are [officially documented](/docs/markdown-features/admonitions)
|
||||||
|
|
Loading…
Add table
Reference in a new issue