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
Why use reference links?
- 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