rspress icon indicating copy to clipboard operation
rspress copied to clipboard

[Feature]: Custom admonitions

Open omonk opened this issue 3 months ago • 3 comments

What problem does this feature solve?

Doc sites using docusaurus or other frameworks may have custom admonitions throughout 100s of files. Allowing them to migrate their admonitions without having to update copy would bolster migration.

https://docusaurus.io/docs/markdown-features/admonitions#customizing-admonitions

What does the proposed API look like?

Example config

themeConfig: {
  admonitions: {
    extensions: ['branded-warning'],
    uiComponents: [path.join(__dirname, 'components', 'CustomAdmonition.tsx')]
  },
},
const CustomAdmonition = ({ level, children }: { level: string }) => {
   if(level === "branded-warning") {
       return <BrandedWarningAdmonition>{children}</BrandedWarningAdmonition>
   }
}

omonk avatar Sep 03 '25 12:09 omonk

In Rspress, we've been calling admonition as container for a while, so I prefer markdown.container

ref: https://github.com/web-infra-dev/rspress/blob/73e84b61778eb5f0e7d80580f8bc095c696c18aa/packages/core/src/node/mdx/remarkPlugins/containerSyntax.ts#L3

Our current grammar has certain differences from Docusaurus, and I believe we may not be able to align all of Docusaurus' configurations. However, it can be determined that we need to refactor the remark plugin related to the container to expose certain configuration options.

So we have a long way to go to align all the configurations of Docusaurus, perhaps we can first extract the Container into a React component first for them.

some small tasks here:

  1. extract Container as React Component

<Container> </Container>

  1. discuss custom configuration items of markdown.container

...

ref:

  • https://vitepress.dev/guide/markdown#custom-containers

  • https://fumadocs.dev/docs/headless/mdx/remark-admonition

SoonIter avatar Sep 08 '25 11:09 SoonIter

Thanks for the details @SoonIter - if I find some time I will have a look at contributing

omonk avatar Sep 08 '25 12:09 omonk

https://github.com/web-infra-dev/rspress/pull/2708#issuecomment-3484944346

SoonIter avatar Nov 05 '25 11:11 SoonIter