rehype-resolve-markdown-links
v0.1.0
Published
A rehype plugin to resolve markdown links to absolute paths
Readme
rehype-resolve-markdown-links
A rehype plugin that resolves relative markdown links into absolute URL paths.
Example
Given this file structure:
content/
getting-started/
intro.mdx
quick-start.md
references/
core.md
react/
button.md
web/
button.mdAnd this configuration with rootDir: './content':
| Source file | Markdown | HTML output |
| -------------------------------- | -------------------------------- | ------------------------------------------------- |
| references/react/button.md | [Web Button](../web/button.md) | <a href="/references/web/button">Web Button</a> |
| references/react/button.md | [Editor](../core.md#editor) | <a href="/references/core#editor">Editor</a> |
| getting-started/quick-start.md | [Intro](./intro.mdx) | <a href="/getting-started/intro">Intro</a> |
Install
npm install rehype-resolve-markdown-linksUsage
import { rehypeResolveMarkdownLinks } from 'rehype-resolve-markdown-links'
import rehypeStringify from 'rehype-stringify'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import { unified } from 'unified'
const file = await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeResolveMarkdownLinks, { rootDir: './content' })
.use(rehypeStringify)
.process(markdown)Options
rootDir
Required. The root directory of your content files. Output links are generated relative to this directory.
License
MIT
