Skip to main content

Links

4 min readStableBeginner

Write links the plain Markdown way and OwnDocs picks the behavior from the destination. A trailing .mdx or .md is stripped from the href first, then the result decides the rendering: internal paths go through the Next.js Link component for client-side navigation, external URLs open in a new tab with rel="noopener noreferrer", and # targets stay on the page.

Quick Start

One internal path, written as an ordinary Markdown link.

Introduction

quick-start.md
Markdown
[Introduction](/getting-started/introduction)

Adding Options

Internal and external side by side

Both forms sit in the same sentence, and only the external one gets the new-tab treatment.

Read the code blocks page, then check the Next.js documentation.

internal-and-external.md
Markdown
Read the [code blocks page](/features/code/code-blocks), then check the
[Next.js documentation](https://nextjs.org/docs).

Titles

A quoted string after the destination becomes the title attribute, which browsers show as a tooltip on hover. It works on internal and external links alike.

Hover Lists or the Next.js docs.

titles.md
Markdown
Hover [Lists](/features/markdown/lists 'Nesting and task lists') or the
[Next.js docs](https://nextjs.org/docs 'App Router reference').

Wrap the destination in angle brackets when it contains spaces, as in [text](</my page>), and the parser encodes them for you.

Advanced

Anchors and relative paths

Every heading gets an id slugified from its text, so ## Adding Options answers to #adding-options. Relative paths resolve against the current page, and the last two links below land on the same route because the extension is dropped.

anchors-and-relative.md
Markdown
- Anchor: [Jump to Adding Options](#adding-options)
- Relative with extension: [Lists](./lists.mdx)
- Relative without extension: [Lists](./lists)

Stripping runs on every href, external ones included, so [Spec](https://example.com/spec.md) requests https://example.com/spec. Point at a raw file through a query string or a redirect instead.

Move the destination out of the sentence and give it a label. The full form names the label in a second bracket pair; the collapsed form leaves that pair empty and reuses the link text as the label. Definitions can sit anywhere in the file and never render.

The App Router and the MDX guide both cover routing. The same definition also backs an image: OwnDocs icon.

reference-links.md
Markdown
The [App Router][next-router] and the [MDX guide][mdx-guide] both cover routing.
The same definition also backs an image: ![OwnDocs icon][icon].
 
[next-router]: https://nextjs.org/docs/app
[mdx-guide]: https://mdxjs.com/docs/what-is-mdx/
[icon]: /img/icon.png 'OwnDocs icon'

Markdown also allows a shortcut form, [next-router] with no second bracket pair at all. It resolves, but this repo's remark lint rules reject it, so use the collapsed form [next-router][] when you want the label to be the text. For zoomable screenshots, reach for ImageZoom instead of a bare Markdown image.

GFM links bare URLs and email addresses as you type them. Two shapes have no live example on this page, because remark lint asks for an explicit [text](url) link and MDX rejects the angle-bracket form outright.

autolinks.txt
Plain Text
https://example.com      linked as-is
www.example.com          linked, with http:// added
name@example.com         linked as mailto:name@example.com
example.com              plain text, no scheme and no www
<https://example.com>    breaks the build; MDX reads < as JSX

Trailing punctuation stays out of the link, so see https://example.com/a. keeps the full stop as prose.

Footnotes

A [^label] marker in the text plus a [^label]: definition anywhere in the file gives you a numbered reference. Labels can be words rather than digits, and reusing one marker twice points both numbers at the same note.

Reading time is estimated at 200 words per minute1, and the same figure drives the meta bar1.

footnotes.md
Markdown
Reading time is estimated at 200 words per minute[^wpm], and the same figure
drives the meta bar[^wpm].
 
[^wpm]: Set in `lib/reading-time.ts`.

Note bodies do not stay where you wrote them. Every footnote on the page collects into a single Footnotes section at the very bottom, below the last heading, with a back-arrow to each reference.

Options

[text](/path)internal

Renders through the Next.js Link component, so the page swaps without a full reload.

[text](https://example.com)external

Any href starting with http://, https://, or // opens in a new tab with target="_blank" and rel="noopener noreferrer".

[text](#heading-id)anchor

A plain anchor tag that scrolls to the matching heading on the current page. Heading ids are slugified from the heading text.

[text](./page.mdx)relative

A trailing .mdx or .md is stripped, so ./page.mdx and ./page resolve to the same route. The strip applies to external URLs too.

[text](/path "Title")title

Adds a title attribute, shown as a hover tooltip. Single quotes, double quotes, and parentheses all work as delimiters.

[text][label]reference

Full reference link. Pairs with a [label]: /path definition elsewhere in the file.

[label][]reference

Collapsed reference link. The link text doubles as the label.

[label]: /pathdefinition

Defines a reference label. Never renders, and accepts an optional title after the destination.

![alt](/img.png)image

Markdown image. Takes the same title and reference forms as a link.

https://example.comautolink

A bare URL, www. host, or email address becomes a link on its own. GFM only, and this repo's lint rules prefer an explicit link.

[^label]footnote

A footnote reference. Needs a matching [^label]: note text definition, and renders the note in a Footnotes section at the bottom of the page.

Footnotes

  1. Set in lib/reading-time.ts. 2

Was this page helpful?