Repository navigation
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
Hi Docusaurus team,
Love this library - thank you for your awesome work!
I'm looking to link a blog post to a docs page using a relative markdown link, but I receive the following error when I specify [link to doc](../../docs/doc-page.md) in the blog post:
[WARNING] Blog markdown link couldn't be resolved: (../../docs/doc-page.md) in "/home/projects/github-dc5ygn/blog/blog-post.md
On the other hand, using link without the .md ([link to doc](../../docs/doc-page)) extension works fine.
Is there a way I can prevent the broken link while preserving the .md extension? I'm using an Obsidian plugin to convert wikilinks to internal links and need to keep the .md extension for it to work properly.
Reproducible demo
Steps to reproduce
- Go to demo linked above.
- Wait for the site to compile. You should see a warning:
[WARNING] Docs markdown link couldn't be resolved: (../../docs/doc-page.md) in "/home/projects/facebook-docusaurus-mx3fkh/docs/doc-page.md" for version current - In the website preview on the right, click the menu button (three bars).
- Click Blog.
- Under the "blog-post" title click "link to doc".
- You should see a "Page Not Found" error.
- Edit "blog-post.md" to exclude ".md" from the link:
[link to doc](../../docs/doc-page) - Complete steps 2-5. Link should now work correctly.
Expected behavior
The link [link to doc](../../docs/doc-page) should work regardless of whether or not .md is specified.
Actual behavior
The link [link to doc](../../docs/doc-page) only works when .md is omitted.
Your environment
- Public source code: See demo link above
- Public site URL: See demo link above
- Docusaurus version used: 2.4.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Node.js 16.20.0
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): N/A
Self-service
- I'd be willing to fix this bug myself.
Activity
slorber commentedon Jul 3, 2023
Yes, it does not work, because currently the relative link resolution is a plugin-specific feature and not a Docusaurus core feature.
I'd like to support cross-plugin relative links but it would require the core engine to somehow maintain a "file path -> URL path" mapping, and we probably need additional plugin lifecycle hooks for that.
Note: if you use Docs versioning, once your docs get versioned, the docs copy will be at a different location and it might break your relative links that are not linking to the same current version (I mean: a relative link from v1.3 to v1.3 won't break, but a v1.3 relative link to a blog post might break when the doc is moved from
./docsto./versioned_docs/1.3).quinn-p-mchugh commentedon Jul 3, 2023
Hi @slorber,
Thanks for confirming! I now see this is noted in the documentation here.
Good to know regarding doc versioning. Fortunately, I do not have a need for versioned docs at this time.
Seems like I might be able to workaround this by using regular expressions to remove the
.mdin the GitHub Obsidian Publisher settings, but we'll see.Very much appreciate your help.
ADNANALISALHADABY commentedon Aug 28, 2023
feat(website): Integrate tutorial with docs
feat(website): Integrate tutorial with docs
feat(website): Integrate tutorial with docs
feat(website): Integrate tutorial with docs
AMD-NICK commentedon Jan 29, 2025
related #3250
octogonz commentedon Aug 11, 2026
I encountered this same issue. A couple notes:
The classic workaround was URL links, which is what Docusaurus's own blog does. For example it uses
/docs/api/docusaurus-config#markdownin pages coming from the blog to the docs. The corresponding config would be:onBrokenMarkdownLinks: 'warn'withonBrokenLinksandonBrokenAnchorsset tothrow. It works, but it means you need to memorize two different linking syntaxes, and every time you write a hyperlink, you now must stop and ask "is the target URL under a different plugin instance?" Nor does it help the original reporter, who said they need the.mdextension preserved for Obsidian tooling.Docusaurus 3.9.0 added an API that can provide a better workaround.
siteConfig.markdown.hooks(#11283) allowsonBrokenMarkdownLinksto be a function, andresolveMarkdownLinksuses its return value to replace the link URL. Since the hook only fires for links Docusaurus already failed to resolve, this approach won't change the behavior of any link that already works today. Pair it with a small plugin that usesallContentLoaded()to build a site-wide map of source file path to permalink, and relative.mdlinks work in every direction. There are probably feature interactions that break, so official support would still be superior to this workaround.Below is my script in case anyone else finds it helpful:
crossPluginLinks.ts
gauranshahuja commentedon Sep 9, 2026
I'd like to work on this.
Plan, building on @slorber's sketch above and @octogonz's workaround: a core source-file-path → permalink registry, filled in
allContentLoadedby the docs, blog and pages plugins (multi-instance and versioned docs included), and consulted byresolveMarkdownLinksin@docusaurus/utilsas a fallback after the existing per-plugin lookup, so any link that resolves today is unchanged. Relative.mdlinks then work in every direction, and the.mdextension the original report needs is preserved.I'll post a short design note here (registry shape, where the lifecycle hook lands, how versioned docs are keyed) before opening the PR, so the approach can be checked first.
gauranshahuja commentedon Sep 9, 2026
Edit: superseded by my later note below and by #12431, which build the registry from route metadata instead of adding a plugin lifecycle. Leaving this here for the record.
Design note before I open the PR, building on @slorber's "file path -> URL path" sketch and @octogonz's hook based workaround.
Registry: a site wide Map from source path to permalink, owned by core and exposed to plugins on LoadContext (working name siteSourceToPermalink). Keys are the same @site/... aliased paths the docs, blog and pages plugins already use in their own sourceToPermalink maps, so versioned docs (@site/versioned_docs/version-1.0/x.md) and multi instance docs (@site/community/x.md) are keyed by their real file location with no special casing.
Filling it: a new optional plugin lifecycle, getSourceToPermalink({content}), returning that instance's map. Core calls it for every loaded plugin and rebuilds the registry in executeAllPluginsAllContentLoaded, just before the allContentLoaded hooks. reloadPlugin goes through the same function, so dev server reloads stay correct (the case #10185 fixed with the mutable maps).
Lookup: resolveMarkdownLinkPathname in @docusaurus/utils takes an optional siteSourceToPermalink and tries the same candidate paths against it only after the per plugin map misses. Links that resolve today are untouched. onBrokenMarkdownLinks still fires when both miss, so the hook workaround keeps working. Query and hash handling stay in the remark plugin.
Known limits, unchanged from today: a relative link written in docs/ breaks after docs:version copies the file one directory deeper (site absolute /blog/post.md is the stable form, I will document it), and localized targets are keyed by their i18n/ path.
Is this shape acceptable, in particular a new lifecycle rather than core reading allContent by plugin name?
gauranshahuja commentedon Sep 10, 2026
Update: this is now implemented and tested on my branch, PR incoming. Design note below, as promised. Building on @slorber's "core maintains a file path → URL path mapping" comment above and @octogonz's workaround plugin. (AI-assisted)
Goal
A
.md/.mdxlink whose target is owned by another plugin instance (docs → blog, blog → docs, pages → docs, docs instance A → docs instance B) resolves to the target's permalink, with the same link syntax that already works inside a plugin. Every link that resolves today keeps resolving exactly as it does now.1. Registry shape
Nothing new: the existing
SourceToPermalinkmap (Map<'@site/<posix path>', permalink>), just site-wide. Keeping the same key format meansresolveMarkdownLinkPathname()in@docusaurus/utilsis reused unchanged for the fallback, called with the site-wide map andcontentPaths = {contentPath: siteDir}:/blog/2023-01-01-hello.md→<siteDir>/blog/2023-01-01-hello.md../blog/2023-01-01-hello.md→ relative to the linking file@site/blog/2023-01-01-hello.md→ direct lookup2. Who fills it: core, from the routes. No new lifecycle hook needed.
Since #10457 every route emitted by docs, blog and pages carries
metadata.sourceFilePath(relative tositeDir). Core builds the site-wide map right afterloadPlugins():That gives multi-instance, versioned docs and i18n for free, and any third-party content plugin joins the moment it sets
sourceFilePathon its routes (which it should already do for the last-updated / sitemap metadata). If two routes point at the same source file, the first one wins and we log a warning; in practice this only happens with duplicated content. An explicit "register a source without a route" API can be added later if a plugin ever needs it; I'd rather not add plugin API surface in v1.3. Resolution order in the
resolveMarkdownLinksremark pluginresolveMarkdownLink(unchanged, always first);null, the site-wide lookup;onBrokenMarkdownLinksas today.Because the plugin's own map wins,
./intro.mdinside docs keeps pointing at the docs page even ifsrc/pages/intro.mdexists. The error message drops the "within the current plugin" wording.4. Getting the map into the MDX loader (the part that needs a decision)
configureWebpackruns once, but content reloads many times in dev (the TODO incontentHelpers.ts, #10185). So the loader must read from one object that stays stable for the life of the dev server and is refreshed in place. Proposal:{sourceToPermalink: Map}+ aresolve()helper), created once perloadSite()and reused acrossreloadSite()/reloadSitePlugin()(both currently rebuildProps; the holder is carried over and refilled afterloadPlugins());LoadContext(name to be bikeshedded;context.markdownLinks?), and docs / blog / pages pass it tocreateMDXLoaderItem()as a new optionalsiteMarkdownLinksoption, next tositeDirandmarkdownConfig. Plugins that don't pass it get today's behaviour.Alternatives I considered and would rather not do: a module-level singleton in
@docusaurus/utilskeyed bysiteDir(works, zero plugin changes, but hidden global state), or attaching the map to the webpack compiler from a core webpack plugin (works, but the loader would depend on an undocumented compiler property).Once this exists, the per-plugin mutable
contentHelpersmaps could be retired in a follow-up (docs/blog/pages would resolve through the same holder, with their own content paths first), which is the cleanup #10185 was asking for. Out of scope for this PR.5. Versioned docs
Keys are the real file paths, so nothing special is needed:
../docs/x.mdfrom a blog post hitsdocs/x.md(the current version, i.e./docs/next/xon a versioned site), while../versioned_docs/version-1.0/x.mdhits 1.0. The caveat @slorber raised still applies: a relative link fromdocs/x.mdto../blog/post.mdgets one level deeper when the doc is copied intoversioned_docs/version-1.3/. Site-root links (/blog/post.md) and@site/blog/post.mdsurvive versioning, so the docs page will recommend those for cross-plugin links.6. i18n
The map is built per locale build, from the file actually used for each route (translated file when it exists, default file otherwise). A cross-plugin link written against the default-locale path still resolves when the target is not translated, and falls back to
onBrokenMarkdownLinkswhen it is; that link is broken today anyway, so no regression. Registering the default-locale source alongside the translated one is a possible follow-up.7. Tests / PR scope
@docusaurus/utils:resolveMarkdownLinkPathnamewithcontentPath = siteDir;onBrokenMarkdownLinks;markdown-features-links.mdx, which currently documents the limitation.Target size is a few hundred lines, one PR. If you'd prefer the
LoadContextaddition split out first, I can do that.