Use when creating Docusaurus plugins — write remark transformers for markdown AST, rehype transformers for HTML/HAST, lifecycle plugins that add routes/webpack config/global data via loadContent and contentLoaded, theme plugins and swizzled components, and content plugins for custom data sources. Triggers on tasks involving custom remark/rehype plugins, content plugins, theme plugins, or Docusaurus lifecycle hooks.
71
89%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
// Remark plugin - transforms markdown AST
module.exports = function remarkPlugin(options = {}) {
return async function transformer(ast, vfile) {
const { visit } = require('unist-util-visit');
visit(ast, 'link', (node) => {
// Transform nodes
node.data = node.data || {};
node.data.hProperties = { className: 'custom' };
});
return ast;
};
};
// In docusaurus.config.js:
// remarkPlugins: [require('./plugins/my-plugin')]Start here — pick the type from what you need to change, then open the matching reference file:
| You want to… | Use | Reference |
|---|---|---|
| Change markdown syntax/content before HTML | Remark | remark-plugins.md |
| Change the generated HTML | Rehype | rehype-plugins.md |
| Add routes, webpack config, or global build data | Lifecycle | lifecycle-plugins.md |
| Override or wrap UI components | Theme | theme-plugins.md |
| Load a custom content source (CMS, API, files) | Content | content-plugins.md |
unist-util-visit for AST traversalloadContent(), contentLoaded(), postBuild()Detailed guides for each plugin type: