Documentation/content/markdown/using-links.md

113 lines
3.4 KiB
Markdown
Raw Normal View History

---
eleventyNavigation:
key: UsingLinks
title: Using Links
parent: Markdown
order: 30
---
2022-07-22 00:27:57 -07:00
You can use links to refer to other articles, sections in articles or other websites.
## Links with description
2022-07-22 00:27:57 -07:00
It is always good for readability to not only paste a URL into your text but to provide
a description of your link. Only the description of the link will be in the rendered form of
2022-07-22 00:27:57 -07:00
your text and the link will be added as an HTML hyperlink.
2022-07-22 00:27:57 -07:00
Hyperlinks have the following markup: `[Link description](link-url)`.
For example:
Lint the documentation (#626) # Changelog The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Removed - Disable the Markdownlint rule MD024 (`Multiple headings with the same content`). ## Fixed - Syntax errors in `.markdownlint.yaml`. - Markdownlint issues: - Heading levels should only increment by one level at a time([MD001](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md001.md)) - Hard tabs ([MD010](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md010.md)) - Reversed link syntax ([MD011](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md011.md)) - Dollar signs used before commands without showing output ([MD014](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md014.md)) - Multiple top-level headings in the same document ([MD025](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md025.md)) - Trailing punctuation in heading ([MD026](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md026.md)) - Ordered list item prefix([MD029](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md029.md)) - Emphasis used instead of a heading([MD036](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md036.md)) - Fenced code blocks should have a language specified ([MD040](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md040.md)) - Link fragments should be valid ([MD051](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md051.md)) - Link text should be descriptive ([MD059](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md059.md)) - Prettier issues. Reviewed-on: https://codeberg.org/Codeberg/Documentation/pulls/626 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: Javier Pérez <walpo@noreply.codeberg.org> Co-committed-by: Javier Pérez <walpo@noreply.codeberg.org>
2025-06-14 06:39:01 -07:00
```markdown
[Link to Codeberg](https://codeberg.org/)
```
Gets rendered as:
[Link to Codeberg](https://codeberg.org/)
## Links without description
2022-07-22 00:27:57 -07:00
To add a link using the URL within your text use `<` and `>` to mark the link.
For example, if you want to add a link to `https://codeberg.org/`, add `<https://codeberg.org>` to your
text. This will render as <https://codeberg.org/>.
You can also just add the link to your text normally to have the same effect: <https://codeberg.org>.
2022-07-22 00:27:57 -07:00
However it is easier to navigate to links if they are explicitly marked by the less than `<` and greater than `>` characters.
## URIs and URLs
2022-07-22 00:27:57 -07:00
You can link to another article by specifying the file or path name URI (a URL, without specifying the protocol and domain).
For example, you can link to the introductory article of this section of the documentation by using its
path name in the link:
Lint the documentation (#626) # Changelog The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Removed - Disable the Markdownlint rule MD024 (`Multiple headings with the same content`). ## Fixed - Syntax errors in `.markdownlint.yaml`. - Markdownlint issues: - Heading levels should only increment by one level at a time([MD001](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md001.md)) - Hard tabs ([MD010](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md010.md)) - Reversed link syntax ([MD011](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md011.md)) - Dollar signs used before commands without showing output ([MD014](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md014.md)) - Multiple top-level headings in the same document ([MD025](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md025.md)) - Trailing punctuation in heading ([MD026](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md026.md)) - Ordered list item prefix([MD029](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md029.md)) - Emphasis used instead of a heading([MD036](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md036.md)) - Fenced code blocks should have a language specified ([MD040](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md040.md)) - Link fragments should be valid ([MD051](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md051.md)) - Link text should be descriptive ([MD059](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md059.md)) - Prettier issues. Reviewed-on: https://codeberg.org/Codeberg/Documentation/pulls/626 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: Javier Pérez <walpo@noreply.codeberg.org> Co-committed-by: Javier Pérez <walpo@noreply.codeberg.org>
2025-06-14 06:39:01 -07:00
```markdown
2022-07-22 00:27:57 -07:00
[Link to introductory article](/markdown/)
```
This is rendered as:
2022-07-22 00:27:57 -07:00
[Link to introductory article](/markdown/)
2022-07-22 00:27:57 -07:00
You can also link to a heading in an article by specifying the heading using a hash character `#`.
2022-07-22 00:27:57 -07:00
For example, you can link to the heading on "Links without description" in this same article by using:
Lint the documentation (#626) # Changelog The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Removed - Disable the Markdownlint rule MD024 (`Multiple headings with the same content`). ## Fixed - Syntax errors in `.markdownlint.yaml`. - Markdownlint issues: - Heading levels should only increment by one level at a time([MD001](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md001.md)) - Hard tabs ([MD010](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md010.md)) - Reversed link syntax ([MD011](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md011.md)) - Dollar signs used before commands without showing output ([MD014](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md014.md)) - Multiple top-level headings in the same document ([MD025](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md025.md)) - Trailing punctuation in heading ([MD026](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md026.md)) - Ordered list item prefix([MD029](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md029.md)) - Emphasis used instead of a heading([MD036](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md036.md)) - Fenced code blocks should have a language specified ([MD040](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md040.md)) - Link fragments should be valid ([MD051](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md051.md)) - Link text should be descriptive ([MD059](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md059.md)) - Prettier issues. Reviewed-on: https://codeberg.org/Codeberg/Documentation/pulls/626 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: Javier Pérez <walpo@noreply.codeberg.org> Co-committed-by: Javier Pérez <walpo@noreply.codeberg.org>
2025-06-14 06:39:01 -07:00
```markdown
[Link to the "links-without-description" section](#links-without-description)
```
This is rendered as:
[Link to the "links-without-description" section](#links-without-description)
2022-07-22 00:27:57 -07:00
You can link to another article's heading using the same syntax.
2022-07-22 00:27:57 -07:00
For example, you can link to the heading on "Bold" in the article "Introduction to Markdown" by using:
Lint the documentation (#626) # Changelog The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Removed - Disable the Markdownlint rule MD024 (`Multiple headings with the same content`). ## Fixed - Syntax errors in `.markdownlint.yaml`. - Markdownlint issues: - Heading levels should only increment by one level at a time([MD001](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md001.md)) - Hard tabs ([MD010](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md010.md)) - Reversed link syntax ([MD011](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md011.md)) - Dollar signs used before commands without showing output ([MD014](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md014.md)) - Multiple top-level headings in the same document ([MD025](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md025.md)) - Trailing punctuation in heading ([MD026](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md026.md)) - Ordered list item prefix([MD029](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md029.md)) - Emphasis used instead of a heading([MD036](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md036.md)) - Fenced code blocks should have a language specified ([MD040](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md040.md)) - Link fragments should be valid ([MD051](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md051.md)) - Link text should be descriptive ([MD059](https://github.com/DavidAnson/markdownlint/blob/v0.38.0/doc/md059.md)) - Prettier issues. Reviewed-on: https://codeberg.org/Codeberg/Documentation/pulls/626 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: Javier Pérez <walpo@noreply.codeberg.org> Co-committed-by: Javier Pérez <walpo@noreply.codeberg.org>
2025-06-14 06:39:01 -07:00
```markdown
[Link to the bold section](/markdown/introduction-to-markdown/#bold)
```
This is rendered as:
2022-07-22 00:27:57 -07:00
[Link to the bold section](/markdown/introduction-to-markdown/#bold)
## Alternative link syntax
The link parser used in Forgejo can also work with the _double square brackets_ syntax in issues and
other places where markdown is rendered:
```markdown
[[https://codeberg.org/]]
```
will get rendered as <https://codeberg.org>.
You can also give a link description, as with the regular markdown syntax:
```markdown
[[This is a link to Codeberg|https://codeberg.org]]
```
will be rendered as [This is a link to Codeberg](https://codeberg.org).
This also works for relative links:
```markdown
[[This is a link to the markdown section of the docs|/markdown/]]
```
will be rendered as [This is a link to the markdown section of the docs](/markdown/).
{% admonition "warning" %}
Be aware that this syntax is 'inverted' compared to the one that [MediaWiki](https://www.mediawiki.org)
uses (i.e. `[[https://example.com|link title]]`).
For compatibility reasons, Forgejo can also convert those links, but only if full paths are specified.
This means `[[https://example.com|link title]]` will also be converted to "[link title](https://example.com)".
But `[[example.com|link title]]` will result in a broken link!
{% endadmonition %}