-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
refactor: normalize Markdown linkification behavior, elaborate in documentation #7248
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b864bc2
refactor: normalize Markdown linkification behavior, elaborate in doc…
Josh-Cena 45ed34f
fix broken links
Josh-Cena ab51438
allow links to be relative to site root
Josh-Cena f11de84
fix test
Josh-Cena bb37bff
minor doc update
Josh-Cena 3a131b4
Update website/docs/guides/markdown-features/markdown-features-links.md
Josh-Cena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...docusaurus-plugin-content-docs/src/markdown/__tests__/__fixtures__/docs/doc2.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
website/docs/guides/markdown-features/markdown-features-links.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
id: links | ||
description: Links to other pages in Markdown | ||
slug: /markdown-features/links | ||
--- | ||
|
||
# Markdown links | ||
|
||
There are two ways of adding a link to another page: through a **URL path** and a **file path**. | ||
|
||
```md | ||
- [URL path to another document](./installation) | ||
- [file path to another document](./installation.md) | ||
``` | ||
|
||
URL paths are unprocessed by Docusaurus, and you can see them as directly rendering to `<a href="./installation">`, i.e. it will be resolved according to the page's URL location, rather than its file-system location. | ||
|
||
If you want to reference another Markdown file **included by the same plugin**, you could use the relative path of the document you want to link to. Docusaurus' Markdown loader will convert the file path to the target file's URL path (and hence remove the `.md` extension). | ||
|
||
For example, if you are in `docs/folder/doc1.md` and you want to reference `docs/folder/doc2.md`, `docs/folder/subfolder/doc3.md` and `docs/otherFolder/doc4.md`: | ||
|
||
```md title="docs/folder/doc1.md" | ||
I am referencing a [document](doc2.md). | ||
|
||
Reference to another [document in a subfolder](subfolder/doc3.md). | ||
|
||
[Relative document](../otherFolder/doc4.md) referencing works as well. | ||
``` | ||
|
||
Relative file paths are resolved against the current file's directory. Absolute file paths, on the other hand, are resolved relative to the **content root**, usually `docs/`, `blog/`, or [localized ones](../../i18n/i18n-tutorial.md) like `i18n/zh-Hans/plugin-content-docs/current`. | ||
|
||
Absolute file paths can also be relative to the site directory. However, beware that links that begin with `docs/` or `blog/` are **not portable** as you would need to manually update them if you create new doc versions or localize them. | ||
Josh-Cena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```md | ||
You can write [links](/otherFolder/doc4.md) relative to the content root (`/docs/`). | ||
|
||
You can also write [links](/docs/otherFolder/doc4.md) relative to the site directory, but it's not recommended. | ||
``` | ||
|
||
Using relative _file_ paths (with `.md` extensions) instead of relative _URL_ links provides the following benefits: | ||
|
||
- Links will keep working on the GitHub interface and many Markdown editors | ||
- You can customize the files' slugs without having to update all the links | ||
- Moving files around the folders can be tracked by your editor, and some editors may automatically update file links | ||
- A [versioned doc](../docs/versioning.md) will link to another doc of the exact same version | ||
- Relative URL links are very likely to break if you update the [`trailingSlash` config](../../api/docusaurus.config.js.md#trailing-slash) | ||
|
||
:::warning | ||
|
||
Markdown file references only work when the source and target files are processed by the same plugin instance. This is a technical limitation of our Markdown processing architecture and will be fixed in the future. If you are linking files between plugins (e.g. linking to a doc page from a blog post), you have to use URL links. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a typo. It should have been caught because it doesn't make much sense!