EDDYMENS

Eddymens (List page)

Last updated 2022-07-18 14:49:04

How To Reuse Links In Markdown (reference Links)

01: ▄▄ ▄▄ ▄▄▄▄▄▄▄▄▄▄ 02: ▐░░▌ ▐░░▌▐░░░░░░░░░░▌ 03: ▐░▌░▌ ▐░▐░▌▐░█▀▀▀▀▀▀▀█░▌ 04: ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌ 05: ▐░▌ ▐░▐░▌ ▐░▌▐░▌ ▐░▌ 06: ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ 07: ▐░▌ ▀ ▐░▌▐░▌ ▐░▌ 08: ▐░▌ ▐░▌▐░▌ ▐░▌ 09: ▄ ▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄█░▌ 10: ▐░▌▐░▌ ▐░▌▐░░░░░░░░░░▌ 11: ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀

Sometimes you need to use the same URL in different parts of your markdown document and this can be a pain when you need to make changes.

You can search and replace using your text editor. However, if the same link is missing the HTTPS: protocol or www in other places this might not work well.

Markdown has a syntax for reusing links called a link reference.

This involves defining the link or URL by using the following syntax: [link name]: link.com. You can place this definition anywhere in your markdown file. The markdown parser will not render this onto the screen.

You can now use this reference link like so [ description text][link name]. Note how square bracket [] is used in the second part as opposed to the parentheses () you will use when creating a normal markdown anchor link.

Below is a complete example

01: This first line uses the link [here][link] 02: 03: This second line uses the link [as well][link] 04: 05: [link]: https://www.example.com
  • Easy to update links: If you ever need to update a link used in different places you will only have to update the reference definition.
  • Friendlier markdown links: because you get to name your reference whatever you want, you can use names that carry meaning regarding what the link is for. This makes it more pleasant for people reading the actual markdown document.
  • Broken link capture: whenever you use a reference link the parser checks to see if the referenced URL was created before rendering it as a link. This means if the reference does not exist you will quickly notice it, as your page will contain meaningless square brackets.

Here is another article you might like 😊 "Markdown hacks for technical writers"