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
67 changes: 60 additions & 7 deletions packages/docusaurus-utils/src/__tests__/markdownUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,17 +1288,23 @@ describe('admonitionTitleToDirectiveLabel', () => {
`);
});

it('does not transform left-padded directives', () => {
it('transforms space indented directives', () => {
expect(
admonitionTitleToDirectiveLabel(
dedent`
before

:::note Title
:::note 1 space

content
content

:::
:::

:::note 2 spaces

content

:::

after
`,
Expand All @@ -1307,16 +1313,63 @@ describe('admonitionTitleToDirectiveLabel', () => {
).toEqual(dedent`
before

:::note Title
:::note[1 space]

content
content

:::
:::

:::note[2 spaces]

content

:::

after
`);
});

it('transforms tab indented directives', () => {
expect(
admonitionTitleToDirectiveLabel(
`
before

\t:::note 1 tab

\tcontent

\t:::

\t\t:::note 2 tabs

\t\tcontent

\t\t:::

after
`,
directives,
),
).toBe(`
before

\t:::note[1 tab]

\tcontent

\t:::

\t\t:::note[2 tabs]

\t\tcontent

\t\t:::

after
`);
});

it('does not transform admonition without title', () => {
expect(
admonitionTitleToDirectiveLabel(
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-utils/src/markdownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ export function admonitionTitleToDirectiveLabel(

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

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

return `${groups.directive}[${groups.title}]`;
return `${groups.indentation ?? ''}${groups.directive}[${groups.title}]`;
});
}

Expand Down
20 changes: 20 additions & 0 deletions website/_dogfooding/_docs tests/tests/admonitions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ import InfoIcon from "@theme/Admonition/Icon/Info"
</Admonition>
```

## Indented admonitions

See admonition title v2 compat syntax bug: https://github.com/facebook/docusaurus/issues/9507

1. Item 1

:::info Important Considerations

For better experience, try to keep the upgrade experience smooth.

:::

- **Scale-up cluster**

:::caution Warning

Scaling up a cluster may cause several minutes of downtime. Please exercise caution.

:::

## Official admonitions

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