Customizing admonitions not work
pdsuwwz opened this issue · comments
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clear
oryarn clear
command. - I have tried
rm -rf node_modules yarn.lock package-lock.json
and re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
I'm not sure if this is a bug, or is something wrong with my configuration.
I tried the method provided by the official website to customize the admonition wrapper and found that it did not work:
// src/theme/Admonition.js
import React from 'react';
import Admonition from '@theme-original/Admonition';
export default function AdmonitionWrapper(props) {
if (props.type !== 'info') {
return <Admonition title="My Custom Admonition Title" {...props} />;
}
return <Admonition {...props} />;
}
use for markdown:
---
sidebar_position: 1
---
:::aaaa
Custom admonition not work
:::
Actually happening:
Reproducible demo
Steps to reproduce
- Create Admonition wrapper
- use Admonition in markdown
Expected behavior
The Admonition Wrapper style is displayed on the page
Actual behavior
Admonition Wrapper style did not take effect:
Your environment
- Public source code: https://stackblitz.com/edit/github-z2vq8q-5tjzog?file=docs%2Fintro.md,package.json,src%2Ftheme%2FAdmonition%2Findex.js
- Public site URL: https://stackblitz.com/edit/github-z2vq8q-5tjzog?file=docs%2Fintro.md,package.json,src%2Ftheme%2FAdmonition%2Findex.js
- Docusaurus version used: v3.2.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4):
- Operating system and version (e.g. Ubuntu 20.04.2 LTS):
Self-service
- I'd be willing to fix this bug myself.
It’s strange. It worked after I just added admonitions.keywords... but it still doesn’t work in my own project.
It's not strange, it's documented: https://docusaurus.io/docs/markdown-features/admonitions#custom-admonition-type-components
If you don't do what is documented then it's normal that it doesn't work.
but it still doesn’t work in my own project.
That's probably because you don't do what is documented. Make sure your project is v3.x, or read the docs of the exact version your project is using, because things can change across major versions.
Thanks, I have solved this problem.
After several tests, I found that the admonitions.keywords
in my docusaurus.config.ts
file was written in the wrong position, so I closed this issue.