The transformMarkdownRelativePaths plugin is a Remark plugin that automatically transforms relative markdown links to work seamlessly in both development environments (VSCode, GitHub) and production builds. It strips page file extensions and converts relative paths to absolute URLs.
/page.tsx, /page.jsx, /page.js, /page.mdx, /page.md from URLs./ and ../ paths to absolute URLs based on current file locationThe plugin processes markdown links in two phases:
| Original Link | Current File | Transformed Link |
|---|---|---|
./getting-started/page.mdx | /docs/page.mdx | /docs/getting-started |
../api-reference/page.tsx | /docs/guides/page.mdx | /docs/api-reference |
/components/page.tsx | Any file | /components |
../hooks/page.mdx#use-state | /docs/page.mdx | /hooks#use-state |
Always link to page.mdx files using relative paths for the best compatibility:
Use Relative Links for Internal Navigation
./sibling-page/page.mdx../page.mdx./child/page.mdxMaintain GitHub Compatibility
Keep Links Simple and Readable
Avoid Links in Headers
Use Function/Class Names as Link Text
validateInput not Input Validator### Basic Example
```markdown
<!-- In /docs/getting-started/page.mdx -->
# Getting Started
Welcome to our documentation! Check out the [API Reference](../api-reference/page.mdx)
or explore our [Components](../components/page.mdx).
For more detailed guides, see:
- [Installation Guide](./installation/page.mdx)
- [Configuration](./configuration/page.mdx)
- [Troubleshooting](./troubleshooting/page.mdx)
```
<!-- In /docs/guides/page.mdx -->
# User Guides
## Quick Start
Start with our [Getting Started](../getting-started/page.mdx) guide.
## Advanced Topics
Learn about:
- [Custom Hooks](../hooks/page.mdx#custom-hooks)
- [State Management](../state/page.mdx#management)
- [Performance Tips](../performance/page.mdx#optimization)
Given this directory structure:
docs/app/
├── components/
│ ├── page.mdx
│ ├── button/
│ │ └── page.mdx
│ └── input/
│ └── page.mdx
└── guides/
└── getting-started/
└── page.mdx
From /components/input/page.mdx:
<!-- Link to sibling component -->
[Button](../button/page.mdx)
<!-- Link to parent components index -->
[Components Overview](../page.mdx)
<!-- Link to guides -->
[Getting Started](../../guides/getting-started/page.mdx)
The plugin is automatically included when using the docs-infra Next.js plugin:
// next.config.js
const { withDocsInfra } = require('@mui/internal-docs-infra/next');
module.exports = withDocsInfra({
// Your Next.js config
});
You can also use the plugin directly with Remark:
import { remark } from 'remark';
import transformMarkdownRelativePaths from '@mui/internal-docs-infra/pipeline/transformMarkdownRelativePaths';
const processor = remark().use(transformMarkdownRelativePaths);
const result = await processor.process(markdownContent);
The plugin preserves query parameters and URL fragments:
<!-- Input -->
[API Reference](./button/page.mdx?section=props#api-table)
<!-- Output (from /components/page.mdx) -->
/components/button?section=props#api-table
The plugin correctly handles deeply nested directory structures:
<!-- From /components/forms/inputs/text-field/page.mdx -->
<!-- Up two levels to components -->
[Components](../../page.mdx)
<!-- To sibling form component -->
[Select](../select/page.mdx)
<!-- To different top-level section -->
[Guides](../../../guides/page.mdx)
The plugin works out of the box without configuration. It automatically:
/app/ directory structure<!-- In a component documentation file -->
This component works with [`FormProvider`](../form-provider/page.mdx)
and [`useValidation`](../use-validation/page.mdx) hook.
For advanced usage, see the [Integration Guide](../../guides/integration/page.mdx).
<!-- In a function documentation file -->
This function is used by [`validateForm`](../validate-form/page.mdx)
and [`submitForm`](../submit-form/page.mdx).
See the [Component examples](../../components/page.mdx) for usage.
<!-- In an index/overview page -->
## Available Components
- [`Button`](./button/page.mdx) - Interactive button component
- [`Input`](./input/page.mdx) - Text input with validation
- [`Form`](./form/page.mdx) - Form container with state management
## Related Utilities
- [`validateInput`](../utils/validate-input/page.mdx) - Input validation
- [`formatData`](../utils/format-data/page.mdx) - Data formatting helper
/app/ structure