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
51 changes: 51 additions & 0 deletions packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`);
});
Expand Down
6 changes: 4 additions & 2 deletions packages/docusaurus-utils/src/markdownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ export function admonitionTitleToDirectiveLabel(

const directiveNameGroup = `(${admonitionContainerDirectives.join('|')})`;
const regexp = new RegExp(
`^(?<indentation>( +|\t+))?(?<directive>:{3,}${directiveNameGroup}) +(?<title>.*)$`,
`^(?<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}]`;
});
}

Expand Down
14 changes: 14 additions & 0 deletions website/_dogfooding/_docs tests/tests/admonitions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down