feat: support absolute paths with <root>/
prefix in remarkFileCodeBlock
#2665
+119
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR enhances the
remarkFileCodeBlock
plugin to support absolute paths using the<root>/
prefix, in addition to the existing relative path support.Motivation
Previously, users could only reference files using relative paths (
./
or../
), which made it challenging to maintain consistent imports across different documentation locations. When reorganizing docs or referencing files from deeply nested MDX files, users had to use complex relative paths like../../../src/components/Button.tsx
.Changes
1. Enhanced Path Resolution
The plugin now supports three path formats:
./file.tsx
- Relative to current file (existing)../file.tsx
- Relative to parent directory (existing)<root>/path/to/file.tsx
- Absolute from document root (new)2. Implementation
Modified
fileCodeBlock.ts
:docDirectory
parameter to plugin signature<root>/
prefix:Updated
options.ts
:docDirectory
parameter to the plugin3. Usage Example
Before:
After:
Both syntaxes continue to work, providing flexibility for different use cases.
Benefits
Testing
Added comprehensive test coverage including:
All existing tests continue to pass, ensuring no breaking changes.
Closes #ISSUE_NUMBER
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.