| title | Plugin Order Guide | |||
|---|---|---|---|---|
| description | Understanding plugin execution order for correct documentation rendering | |||
| section | Guides | |||
| difficulty | intermediate | |||
| tags |
|
Remark plugins execute in the order they're listed. Order matters!
Warning: Incorrect plugin order is the #1 cause of broken documentation rendering. This guide shows you the correct order and explains why.
flowchart TD
MD[Markdown Input] --> Structural[Structural Plugins]
Structural --> TOC[Table of Contents]
TOC --> Links[Links Plugin]
Links --> Refs[Symbol References]
Refs --> Screenshots[Screenshots]
Screenshots --> Code[Code Highlighting]
Code --> HTML[HTML Output]
style MD fill:#e3f2fd
style HTML fill:#d4edda
style Links fill:#fff3cd
style Refs fill:#ffebee
import { mdsvex } from 'mdsvex';
import remarkMath from 'remark-math';
import {
filetreePlugin,
calloutsPlugin,
collapsePlugin,
mermaidPlugin,
tabsPlugin,
remarkTableOfContents,
linksPlugin,
referencePlugin,
screenshotPlugin,
katexPlugin,
codeHighlightPlugin,
} from '@goobits/docs-engine/plugins';
export default {
preprocess: [
mdsvex({
remarkPlugins: [
// 1. Structural transformations (don't depend on others)
filetreePlugin(),
calloutsPlugin(),
collapsePlugin(),
mermaidPlugin(),
tabsPlugin(),
// 2. Table of contents (needs stable headings)
remarkTableOfContents(),
// 3. Links transformation (before references)
linksPlugin(),
// 4. Symbol references (needs links transformed)
referencePlugin(),
// 5. Screenshots (near end)
screenshotPlugin(),
// 6. Math and code highlighting (last)
remarkMath,
katexPlugin(),
codeHighlightPlugin(),
],
}),
],
};Note: Each section below explains why plugins must run in this specific order.
Plugins that create new markdown structures should run first:
filetreePlugin()- Transforms code blockscalloutsPlugin()- Transforms blockquotescollapsePlugin()- Transforms directive blocksmermaidPlugin()- Transforms code blockstabsPlugin()- Transforms directive blocks
These don't depend on other plugins.
remarkTableOfContents() needs to run before plugins that modify headings or create new ones.
Warning: This is CRITICAL! Getting this wrong breaks symbol references.
Critical: linksPlugin() must run before referencePlugin().
Why?
flowchart LR
subgraph "✅ Correct"
A1[Links Plugin] --> A2[Transforms .md links]
A2 --> A3[References Plugin]
A3 --> A4[Generates new links]
A4 --> A5[✓ Works!]
end
subgraph "❌ Wrong"
B1[References Plugin] --> B2[Generates links]
B2 --> B3[Links Plugin]
B3 --> B4[Breaks generated links]
B4 --> B5[✗ Broken!]
end
style A5 fill:#d4edda
style B5 fill:#ffebee
referencePlugin()generates links (e.g.,{@Symbol}→[Symbol](url))- If
linksPlugin()runs after, it will try to transform these generated links - This breaks the symbol links
screenshotPlugin() should run before codeHighlightPlugin() to ensure screenshot code blocks are processed first.
Syntax highlighting should be the final transformation to code blocks. This ensures all other plugins have finished processing code blocks.
// ❌ WRONG
remarkPlugins: [
referencePlugin(), // Runs first
linksPlugin(), // Breaks symbol links
]// ✅ CORRECT
remarkPlugins: [
linksPlugin(),
referencePlugin(),
]// ❌ WRONG
remarkPlugins: [
codeHighlightPlugin(), // Runs first
filetreePlugin(), // Won't process highlighted code
]// ✅ CORRECT
remarkPlugins: [
filetreePlugin(),
codeHighlightPlugin(), // Runs last
]// ❌ WRONG
remarkPlugins: [
referencePlugin(), // Might add headings
remarkTableOfContents(), // TOC won't include them
]// ✅ CORRECT
remarkPlugins: [
remarkTableOfContents(),
referencePlugin(),
]For a basic docs setup:
remarkPlugins: [
calloutsPlugin(),
tocPlugin(),
linksPlugin(),
codeHighlightPlugin(),
]For all features:
remarkPlugins: [
// Content structure
filetreePlugin(),
calloutsPlugin(),
collapsePlugin(),
mermaidPlugin(),
tabsPlugin(),
// Navigation
remarkTableOfContents(),
// Link processing
linksPlugin(),
// Advanced features
referencePlugin(),
screenshotPlugin(),
// Syntax rendering
remarkMath,
katexPlugin(),
codeHighlightPlugin({
theme: 'dracula',
showLineNumbers: false
}),
]If you're experiencing issues:
- Check the console - Plugin errors often indicate order problems
- Test incrementally - Add plugins one at a time
- Read plugin docs - Each plugin doc notes dependencies
- Use this guide - Follow the recommended order above
| Plugin | Must Run After | Must Run Before |
|---|---|---|
filetreePlugin |
- | codeHighlightPlugin |
calloutsPlugin |
- | - |
collapsePlugin |
- | - |
mermaidPlugin |
- | codeHighlightPlugin |
tabsPlugin |
- | codeHighlightPlugin |
remarkTableOfContents |
Structural plugins | Content plugins |
linksPlugin |
- | referencePlugin |
referencePlugin |
linksPlugin |
- |
screenshotPlugin |
- | codeHighlightPlugin |
codeHighlightPlugin |
All other plugins | - |
Prerequisites: Understanding of remark/rehype plugins
Next Steps:
- Architecture - System design
- Examples - Complete configurations
Related:
- Getting Started - Basic setup