Skip to content

Conversation

@lebalz
Copy link
Contributor

@lebalz lebalz commented Jan 1, 2026

Motivation

Add support for admonition directive class/id shortcuts, as specified in the directive syntax: https://talk.commonmark.org/t/generic-directives-plugins-syntax/444

:::note{.padding--lg #admonition-id-2}

My note

:::

Closes #11641

Test Plan

  • add unit test
  • add dogfooding example at tests/docs/tests/admonitions

Test links

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Jan 1, 2026
@netlify
Copy link

netlify bot commented Jan 1, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit e9278f8
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69590137415e5600088bfbf0
😎 Deploy Preview https://deploy-preview-11642--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that markdown-directives has shortcuts for class/id: https://talk.commonmark.org/t/generic-directives-plugins-syntax/444

What about also adding support for id then?

We would need to document that, yes, otherwise nobody will find out 🤪

@@ -0,0 +1,5 @@
Admonitions with attributes

:::info[Info Title]{.bold}
Copy link
Collaborator

@slorber slorber Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add more examples here, including with 2 classes, and interleaving multiple classes/ids and other non-shortcut attributes?

Looks like in case of duplicate ids, the last one wins in :::info{.c1 #id1 .c2 #id2 hello=world}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - i added more doogfood here: https://deploy-preview-11642--docusaurus-2.netlify.app/tests/docs/tests/admonitions/#admonitions-with-classes

Things to consider when we support passing attributes hello=world:

  • this supports with the current remark-admonition plugin with it's hast-node approach the possibility to provide html attributes as style="color:red" (what actually works as highlighted in the dogfood test).
  • this is actually a really nice feature, but...
  • it brings possible hard regressions with it: when the remark admonition plugin upgrades to mdxJsxFlowElement, props-passing gets more complicated, since react specific code, as the style attribute must be passed as an expression to be compatible with react. This would need some docusaurus-specific parse logic to transform style="color:red" to style={{color: 'red'}}. This can be done (i implemented something here), but i'm not sure wheter you want to maintain this in the longterm?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this is not ideal and I'd rather only support class/ids for now

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Jan 2, 2026
@slorber slorber changed the title fix(mdx-loader): propagate class names to admonitions feat(mdx-loader): add admonitions directive support for class/id shortcuts Jan 2, 2026
@lebalz
Copy link
Contributor Author

lebalz commented Jan 2, 2026

TIL that markdown-directives has shortcuts for class/id: https://talk.commonmark.org/t/generic-directives-plugins-syntax/444

What about also adding support for id then?

We would need to document that, yes, otherwise nobody will find out 🤪

Hi @slorber

Thanks for your review. I think i addressed the highlighted points:

  • Support IDs
    • In 1babe74 i added transformation of admonition headings to a h5 element, s.t. a link can be copied directly. I'm not sure if this was what you intended - otherwise i'm fine to undo this commit 😉
  • Support general attributes - see the comment above regarding implications. I would like to see the feature landing in docusaurus, but i would understand if not...
  • Add docs - best seen in light mode, since infima's shadow setting for the dark mode is not that obvious.

What do you think?

@lebalz lebalz requested a review from slorber January 2, 2026 21:06
@@ -0,0 +1,5 @@
Admonitions with attributes

:::info[Info Title]{.bold}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this is not ideal and I'd rather only support class/ids for now

@lebalz lebalz requested a review from slorber January 3, 2026 11:37
@lebalz
Copy link
Contributor Author

lebalz commented Jan 3, 2026

Thanks for the suggestions - i cleaned up the pr and it should be ready to review again 🙂

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks 👍

@slorber slorber merged commit bf9924a into facebook:main Jan 5, 2026
44 of 45 checks passed
@lebalz lebalz deleted the fix/propagate-classes-to-admonitions branch January 5, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mdx-loader should propagate class names from directives to admonition component

2 participants