Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: elaborate on the usage of MDX plugins #5766

Merged
merged 11 commits into from
Oct 29, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,31 @@ description: Using MDX plugins to expand Docusaurus Markdown functionalities
slug: /markdown-features/plugins
---

You can expand the MDX functionalities, using plugins.
MDX has a built-in plugin system that can be used to customize its behavior, [see plugin documentation](https://mdxjs.com/advanced/plugins/) in official MDX docs.

Docusaurus content plugins support both [Remark](https://github.com/remarkjs/remark) and [Rehype](https://github.com/rehypejs/rehype) plugins that work with MDX.
You might want to customize the behavior of file translations in few ways for instance:

- using existing remark plugin ([see official remark plugin list](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins))
- using existing rehype plugin ([see official rehype plugin list](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins))
- create remark/rehype plugin to introduce new syntax to your MDX
- create remark/rehype plugin to change the HTML output for existing MDX syntax

Some use case examples of introducing new features might be:

- mathml support
- graph visualization
- sheet music generation

Changes to HTML output might be useful if you want to:

- add some additional HTML properties
- change the resulting HTML element for Markdown feature

## What are remark and rehype

Remark is a markdown processor used to parse it into the structured tree. It can be later used programmatically to transform it or compile it into output format. Complete introduction to remark can be found [here](https://github.com/remarkjs/remark).

Rehype is a similar suite of plugins working on the HTML files, capable of transforming them. Complete introduction to rehype can be found [here](https://github.com/rehypejs/rehype).

## Configuring plugins {#configuring-plugins}

Expand Down Expand Up @@ -76,3 +98,13 @@ module.exports = {
```

See more information in the [MDX documentation](https://mdxjs.com/advanced/plugins).

## Creating new rehype/remark plugins

In order to create your own plugins follow those instructions for [remark](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#creating-plugins) or [rehype](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#creating-plugins).

:::tip

Docusaurus provides its own [plugins](https://github.com/facebook/docusaurus/tree/main/packages/docusaurus-mdx-loader/src/remark) that can be inspiration for your next plugin.

:::