Creating Plugins
Learn how to extend Doom by creating custom plugins that add new features, transform content, or integrate external tools.Plugin Basics
A Doom plugin is a function that returns an object conforming to theRspressPlugin interface:
Plugin Structure
Basic Template
plugins/my-plugin/index.ts
Plugin Hooks
config
Modify the user configuration:markdown
Add remark or rehype plugins:addRuntimeModules
Create virtual modules accessible at runtime:addPages
Add custom pages:globalStyles
Add global CSS/SCSS:globalUIComponents
Add components to every page:Creating a Remark Plugin
Remark plugins transform the markdown AST:plugins/my-plugin/remark-my-transform.ts
Example: Custom Embed Plugin
Create a plugin that embeds external content:plugins/embed-plugin/index.ts
Example: Analytics Plugin
Add analytics tracking:plugins/analytics-plugin/index.ts
plugins/analytics-plugin/components/Analytics.tsx
Loading External Data
Load and process external data at build time:Working with AST
Understand the markdown AST structure:Best Practices
- Use TypeScript - Provide type definitions for options
- Document Options - Clearly document all configuration options
- Handle Errors - Gracefully handle missing files or invalid data
- Performance - Minimize build-time operations
- Modularity - Keep plugins focused on one task
- Testing - Test with various configurations
- Naming - Use descriptive, unique plugin names
Testing Plugins
Create a test setup:Publishing Plugins
Share your plugin with others:- Package Structure
- package.json
- Publish to npm