facebook / docusaurus

Easy to maintain open source documentation websites.

Home Page:https://docusaurus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Customizing admonitions not work

pdsuwwz opened this issue · comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn 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:

image

Reproducible demo

https://stackblitz.com/edit/github-z2vq8q-5tjzog?file=docs%2Fintro.md,package.json,src%2Ftheme%2FAdmonition%2Findex.js

Steps to reproduce

  1. Create Admonition wrapper
  2. use Admonition in markdown

Expected behavior

The Admonition Wrapper style is displayed on the page

Actual behavior

Admonition Wrapper style did not take effect:

image
image

Your environment

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.