Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference-style Markdown links are not resolved #6616

Closed
5 of 7 tasks
LeviticusMB opened this issue Feb 5, 2022 · 4 comments · Fixed by #6617
Closed
5 of 7 tasks

Reference-style Markdown links are not resolved #6616

LeviticusMB opened this issue Feb 5, 2022 · 4 comments · Fixed by #6617
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@LeviticusMB
Copy link
Contributor

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and 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

I'm editing my Markdown files in VS Code, and it's very handy to be able to click on Markdown links in VS Code to automatically open the linked Markdown source file when editing, if not just to make sure the link works.

To do this, I need to link to the actual Markdown file. However, Docusaurus will not allow this when running docusaurus build and when running docusaurus start, the it randomly (!?) strips or retains the .md extension (!?).

You obviously know that the file docs/my/text.md will end up at path /docs/my/text so why can't Markdown links go through the same resolution step, so we can easily navigate source code links while editing?

Steps to reproduce

The following operations are defined for [URI]s:

* [info]: Returns metadata about the resource, (via `stat()` for local files or `HEAD` for HTTP resources, for example).
* [list]: Returns metadata about the resource's children (like getting the content of a local directory).

[URI]:    ../api/classes/divine_uri.URI.md
[info]:   ../api/classes/divine_uri.URI.md#info
[list]:   ../api/classes/divine_uri.URI.md#list

Expected behavior

The links all navigate to /docs/api/divine_uri.URI.

Actual behavior

The links all navigate to /docs/api/divine_uri.URI.md, which is a 404.

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Reproducible demo

No response

Self-service

  • I'd be willing to fix this bug myself.
@LeviticusMB LeviticusMB added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Feb 5, 2022
@Josh-Cena Josh-Cena added status: needs more information There is not enough information to take action on the issue. and removed status: needs triage This issue has not been triaged by maintainers labels Feb 5, 2022
@Josh-Cena
Copy link
Collaborator

Hey, we do allow writing Markdown links, and they are documented in multiple places, e.g. https://docusaurus.io/docs/docs-markdown-features#referencing-other-documents

Your issue is that you are using the reference-style Markdown link, while we have a faulty regex that only permits one space between the colon and the text. I will fix that. This style isn't common, so we haven't had people complaining so far...🤦‍♂️

You obviously know that the file docs/my/text.md will end up at path /docs/my/text

Not always. It's up to the individual plugin to convert file paths to URLs, and plugins as of now don't communicate with each other, so the docs plugin can't know the file -> URL mapping of the blog plugin. Therefore, you can't write a link to a doc Markdown file in a blog file. See #6370 for a potential solution

@Josh-Cena Josh-Cena removed the status: needs more information There is not enough information to take action on the issue. label Feb 5, 2022
@Josh-Cena Josh-Cena changed the title Markdown links with .md extension not allowed Reference-style Markdown links are not resolved Feb 5, 2022
@LeviticusMB
Copy link
Contributor Author

Wow that explains my "randomly" comment... My links section actually looked like this:

[info]:   ../api/classes/divine_uri.URI.md#info
[list]:   ../api/classes/divine_uri.URI.md#list
[load]:   ../api/classes/divine_uri.URI.md#load
[save]:   ../api/classes/divine_uri.URI.md#save
[append]: ../api/classes/divine_uri.URI.md#append
[remove]: ../api/classes/divine_uri.URI.md#remove
[query]:  ../api/classes/divine_uri.URI.md#query
[watch]:  ../api/classes/divine_uri.URI.md#watch

and the append and remove links worked while not the others. 😮

Thanks!

@Josh-Cena
Copy link
Collaborator

Yes, see the fix I just made. Our faulty regex only allows one space in between. You can try with the latest canary.

@LeviticusMB
Copy link
Contributor Author

Just FYI my links now work using "@docusaurus/utils": "canary". Thanks again for the quick resolution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants