Replace Plugin
The replace plugin enables embedding and syncing content from external markdown files into your documentation. It supports pulling content from remote repositories, handling frontmatter, and automatically updating embedded content.Features
- Reference Blocks - Embed content from local or remote markdown files
- Multi-Source Support - Pull content from GitHub repositories or local files
- Smart Syncing - Automatically update embedded content during builds
- Frontmatter Handling - Control how frontmatter is merged from referenced files
- Content Slicing - Extract specific sections using anchor links
- Release Notes - Automatically generate release notes from JIRA queries
- Image Normalization - Automatically resolve and copy image paths
- Link Normalization - Fix relative links in embedded content
Configuration
Configure the replace plugin in yourdoom.config.ts:
Plugin Options
Language code for localized content. Set to
null for non-localized docs.Base path for resolving local file references.
Force re-fetching content from remote repositories, bypassing cache.
Reference Configuration
Reference Item
GitHub repository in
owner/repo format for remote sources.Git branch to pull content from.
Path to public assets directory in the source repository.
Array of content sources to embed.
Reference Source
Unique identifier for this reference (used in reference blocks).
Path to the source file, optionally with
#anchor to extract a section.Skip the heading when extracting a section.
How to handle frontmatter from the source file:
ignore- Don’t modify frontmattermerge- Merge source frontmatter with currentremove- Remove all frontmatterreplace- Replace current with source frontmatter
Content processors to apply before embedding (e.g., EJS templates).
Usage
Basic Reference Block
Embed content using reference comments: Markdown (.md):Local File Reference
Embed content from local files:Remote Repository Reference
Embed content from GitHub repositories:Section Extraction
Extract specific sections using anchors:Frontmatter Merging
Control how frontmatter is handled:EJS Template Processing
Process content with EJS templates:Release Notes Integration
Automatically generate release notes from JIRA:Implementation
Plugin Structure
The plugin integrates with Rspress using remark and rehype plugins:packages/doom/src/plugins/replace/index.ts:32-67
Content Resolution
The plugin resolves references during the build:- Parse - Identify reference blocks in markdown
- Resolve - Fetch content from local or remote sources
- Transform - Apply processors and normalize images/links
- Inject - Insert content between reference markers
- Update - Write changes back to disk if content changed
Image Handling
Images from remote sources are automatically handled:- Remote images are copied to your
publicdirectory - Image paths are updated to point to the local copies
- Relative paths are preserved and adjusted
Link Normalization
Relative links in embedded content are automatically fixed:- Links are resolved relative to the source file
- Internal links are adjusted for your site structure
- External links remain unchanged
Auto-Update Behavior
During production builds, the plugin checks if embedded content has changed and automatically updates your source files. You’ll see a warning to commit these changes.
packages/doom/src/plugins/replace/remark-replace.ts:220-231
Best Practices
- Use Descriptive Names - Name references clearly (e.g.,
k8s-install-linuxnotref1) - Version Control - Commit updated reference blocks when warnings appear
- Cache Strategy - Use
force: trueonly when debugging remote content issues - Section Extraction - Prefer extracting specific sections over entire files
- Test Locally - Verify references resolve correctly before pushing
- Document Sources - Add comments explaining where content comes from
Common Patterns
Shared API Documentation
Multi-Product Documentation
Localized Content
Troubleshooting
Reference Not Found
If you see “Reference not found” errors:- Verify the reference name matches the
sourcesconfiguration - Check the
pathis correct and the file exists - For remote repos, ensure the repository and branch are correct
Content Not Updating
If embedded content isn’t updating:- Try using
force: trueto bypass cache - Check that reference markers are correctly formatted
- Verify the source file has actually changed
Anchor Not Found
If anchor extraction fails:- Verify the heading exists in the source file
- Check heading ID generation (special chars are normalized)
- Use heading text instead of ID if needed