diff --git a/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts b/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts index 3134835e26..182c95b05f 100644 --- a/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts +++ b/packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts @@ -1366,6 +1366,57 @@ before \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 `); }); diff --git a/packages/docusaurus-utils/src/markdownUtils.ts b/packages/docusaurus-utils/src/markdownUtils.ts index 62608db49f..a2ca3db101 100644 --- a/packages/docusaurus-utils/src/markdownUtils.ts +++ b/packages/docusaurus-utils/src/markdownUtils.ts @@ -97,14 +97,16 @@ export function admonitionTitleToDirectiveLabel( const directiveNameGroup = `(${admonitionContainerDirectives.join('|')})`; const regexp = new RegExp( - `^(?( +|\t+))?(?:{3,}${directiveNameGroup}) +(?.*)$`, + `^(?<quote>(> ?)*)(?<indentation>( +|\t+))?(?<directive>:{3,}${directiveNameGroup}) +(?<title>.*)$`, 'gm', ); return content.replaceAll(regexp, (substring, ...args: any[]) => { const groups = args.at(-1); - return `${groups.indentation ?? ''}${groups.directive}[${groups.title}]`; + return `${groups.quote ?? ''}${groups.indentation ?? ''}${ + groups.directive + }[${groups.title}]`; }); } diff --git a/website/_dogfooding/_docs tests/tests/admonitions.mdx b/website/_dogfooding/_docs tests/tests/admonitions.mdx index 5094cc36a1..e9f7d858aa 100644 --- a/website/_dogfooding/_docs tests/tests/admonitions.mdx +++ b/website/_dogfooding/_docs tests/tests/admonitions.mdx @@ -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 Admonitions that are [officially documented](/docs/markdown-features/admonitions)