facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
56.68k stars 8.52k forks source link

[Bug]: Using the remark-directive plugin, custom directives cannot be used #9301

Closed guoqqqi closed 1 year ago

guoqqqi commented 1 year ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

I use the remark-directive plugin and want to customize a directive to specify the rendering of part of the markdown file. I cannot obtain the information about the directive in my custom plugin. It is always rendered as <p />

Reproducible demo

https://github.com/guoqqqi/docusaurus-remark-plugin

Steps to reproduce

  1. Enable @docusaurus/plugin-content-docs plugin
  2. Add remark-directive plugin and add it to the docusaurus.config.js file
  3. Create a new custom remark plugin:
    
    import { visit } from 'unist-util-visit';

export const pluginFiled = () => { const transformer = async (ast) => { visit(ast, (node) => { if (node.type === 'textDirective' || node.type === 'leafDirective' || node.type === 'containerDirective') { console.log('node: ', node); const isPluginField = node.name === 'plugin-field'; if (!isPluginField) return; } }); }

return transformer; };

4. Use this directive failed

:::plugin-field 123 :::



**I can't get `node.name` and the `textDirective`, `leafDirective` and `containerDirective` types are not found in the `node.type`**

### Expected behavior

I hope that my instruction information can be read in `node.type`

### Actual behavior

 I cannot obtain the information about the directive in my custom plugin. It is always rendered as  `<p />`

### Your environment

- Public source code:
- Public site URL:
- Docusaurus version used:
- Environment name and version (e.g. Chrome 89, Node.js v18.17.1):
- Operating system and version (e.g. Mac M1):

### Self-service

- [ ] I'd be willing to fix this bug myself.
slorber commented 1 year ago

Remark-directive only works with Docusaurus v3 and is installed by default: that's how we support admonitions now.

Are you using Docusaurus v3? Because this won't work in Docusaurus v2.

If yes please create a repro, I can't help without seeing your code.

slorber commented 1 year ago

Closing because a repro was provided but uses Docusaurus v2, which won't support remark directives.

Please upgrade to Docusaurus v3 (alpha). It's safe, I'm writing marketing material and upgrade guides for the official launch.

You can see in the mdx playground that it works by turning the "remark-directive" option on:

CleanShot 2023-09-14 at 12 47 36