2023-August-28 As of today, this evolving1 article has been on the web for
2021-February-5 In this article, removed most of the information about the Markdown syntax for abbreviations and changed the title to Links and Footnotes in Markdown. To learn about abbreviations in Markdown, which AFAIK are currently2 only available in PHP Markdown Extra,3 see the 2014 version of this article at nancym.tumblr.com/post/59594358553/links-footnotes-and-abbreviations-in-markdown.
2021-February-5 As of today, this article is rendered with the Pandoc universal document converter rather than Goldmark, which is Hugo’s default Markdown renderer. I switched from Goldmark to Pandoc because I was in search of a Markdown flavor that I could plug in to Hugo that supports abbreviations. I did not find that, but I did discover that Pandoc supports some Markdown footnote syntax that Goldmark does not support.4
One reason Markdown5 is so popular is that it is much easier for a human to read and write than HTML. To make Markdown as readable as possible, I like to specify links by reference rather than inline. Some flavors of Markdown, for example PHP Markdown Extra, support footnotes, which also can be specified by reference. I’m writing this article for two reasons:
Here is a table that summarizes what can be specified by reference in Markdown. For completeness, I include the Markdown markup for images, which can also be specified by reference.
What | Inline Markdown | Reference Markdown | Rendered HTML Tags |
---|---|---|---|
link | [linked text][id] | [id]: URL "title" | a |
link | [linked text][] | [linked text]: URL "title"
| a |
image | ![alt text][id] | [id]: URL "title" | img |
footnote | footnoted text[^id] | [^id]: the footnote | sup a |
Tip 1: "title"
is
optional.
Tip 2: id
is case
insensitive.
Tip 3: id
cannot contain
whitespace.
In the Markdown source code examples below, a vertical ellipsis
(⋮
) represents a random number of lines of text and blank
lines that can separate the inline Markdown from the reference
Markdown.
A Markdown tool that I’m testing, and actually using to write this article, is MdCharm.
Here is the Markdown source code for the previous sentence:
A Markdown tool that I'm testing, and actually using to write this article, is [MdCharm][].
⋮
[mdcharm]: https://github.com/zhangshine/MdCharm
An online tool for comparing flavors of Markdown is John MacFarlane’s Babelmark 2.
Here is the Markdown source code for the previous sentence:
An online tool for comparing flavors of Markdown is John MacFarlane's [Babelmark 2][b2].
⋮
[b2]: https://johnmacfarlane.net/babelmark2/
Important: Markdown footnote syntax is not standardized and the footnote syntax used in the source of this article does not work in some Markdown renderers.
Most Markdown tools do not support abbreviations. Instead, you need to use raw HTML to specify abbreviations.6
Here is the Markdown source code for the previous sentence:
Most Markdown tools do not support abbreviations. Instead, you need to use raw HTML to specify abbreviations.[^abbr]
⋮
[^abbr]: In a desktop web browser, an abbreviation is usually rendered as a mouseover pop-up definition. In <abbr title="Hypertext Markup Language">HTML</abbr>4, abbreviations are specified using the `abbr` or `acronym` tag. In HTML5, only the `abbr` tag is used.
Some Markdown parsers, for example Blackfriday, Mmark, Pandoc, and PHP Markdown Extra, also support inline footnotes.7
Here is the Markdown source code for the previous sentence:
Some Markdown parsers, for example Blackfriday, Mmark, Pandoc, and PHP Markdown Extra, also support inline footnotes.^[Footnotes are also known as endnotes.]
Here is a list of the Markdown syntax that I used to create this article.
Here is the source code of the “main matter”8 of this article. This does not include the source code of the header, TOC, News section, or anything below this sentence (other than the footnotes that are specified in the source code above this sentence).
<!-- NOTE TO SELF: This entire file is *published* in links-footnotes-markdown. -->
## About Markdown
One reason Markdown[^markdown] is so popular is that it is much easier for a human to read and write than HTML. To make Markdown as readable as possible, I like to specify links by reference rather than inline. Some flavors of Markdown, for example [PHP Markdown Extra][mdextra], support footnotes, which also can be specified by reference. I'm writing this article for two reasons:
1. As a note to myself about the by-reference syntax of links, footnotes, and images.
1. To create a Markdown file that I can use to test Markdown tools. All flavors of Markdown support by-reference links, but only some support footnotes. I'll use the Markdown source code of *this* article to test tools.
[mdextra]: https://michelf.ca/projects/php-markdown/extra/
[^markdown]: Markdown is a [lightweight markup language][lml] that I wrote about in <https://nancym.tumblr.com/post/43431761935/maybe-if-i-learn-markdown-ill-blog-more>.
[lml]: https://wikipedia.org/wiki/Lightweight_markup_language
## Cheatsheet for By-Reference Markdown Syntax
Here is a table that summarizes what can be specified by reference in Markdown. For completeness, I include the Markdown markup for images, which can also be specified by reference.
What | Inline Markdown | Reference Markdown | Rendered<br>HTML Tags
:------------- | :------------------- | :--------------------- | :-------
link | `[linked text][id]` | `[id]: URL "title"` | `a`
link | `[linked text][]` | `[linked text]: URL "title"` | `a`
image | `![alt text][id]` | `[id]: URL "title"` | `img`
footnote | `footnoted text[^id]` | `[^id]: the footnote` | `sup a`
***Tip 1:*** `"title"` is optional.
***Tip 2:*** `id` is case insensitive.
***Tip 3:*** `id` cannot contain whitespace.
## Link Examples
In the Markdown source code examples below, a vertical ellipsis (<code>⋮</code>) represents a random number of lines of text and blank lines that can separate the inline Markdown from the reference Markdown.
### By-Reference Link Example 1
A Markdown tool that I'm testing, and actually using to write this article, is [MdCharm][].
[mdcharm]: https://github.com/zhangshine/MdCharm
Here is the Markdown source code for the previous sentence:
```
A Markdown tool that I'm testing, and actually using to write this article, is [MdCharm][].
⋮
[mdcharm]: https://github.com/zhangshine/MdCharm
```
### By-Reference Link Example 2
An online tool for comparing flavors of Markdown is John MacFarlane's [Babelmark 2][b2].
[b2]: https://johnmacfarlane.net/babelmark2/
Here is the Markdown source code for the previous sentence:
An online tool for comparing flavors of Markdown is John MacFarlane's [Babelmark 2][b2].
⋮
[b2]: https://johnmacfarlane.net/babelmark2/
## Footnote Examples
***Important:***
Markdown footnote syntax is not standardized and the footnote syntax used in the source of this article does not work in some Markdown renderers.
<!--
TODO MAYBE:
For example [Goldmark](https://github.com/yuin/goldmark), which is Hugo's default Markdown renderer.
-->
### By-Reference Footnote Example
Most Markdown tools do not support abbreviations. Instead, you need to use raw HTML to specify abbreviations.[^abbr]
[^abbr]: In a desktop web browser, an abbreviation is usually rendered as a mouseover pop-up definition. In <abbr title="Hypertext Markup Language">HTML</abbr>4, abbreviations are specified using the `abbr` or `acronym` tag. In HTML5, only the `abbr` tag is used.
Here is the Markdown source code for the previous sentence:
```
Most Markdown tools do not support abbreviations. Instead, you need to use raw HTML to specify abbreviations.[^abbr]
⋮
[^abbr]: In a desktop web browser, an abbreviation is usually rendered as a mouseover pop-up definition. In <abbr title="Hypertext Markup Language">HTML</abbr>4, abbreviations are specified using the `abbr` or `acronym` tag. In HTML5, only the `abbr` tag is used.
```
### Inline Footnote Example
Some Markdown parsers, for example Blackfriday, Mmark, Pandoc, and PHP Markdown Extra, also support inline footnotes.^[Footnotes are also known as endnotes.]
Here is the Markdown source code for the previous sentence:
```
Some Markdown parsers, for example Blackfriday, Mmark, Pandoc, and PHP Markdown Extra, also support inline footnotes.^[Footnotes are also known as endnotes.]
```
## Markdown Used in This Article
Here is a list of the Markdown syntax that I used to create this article.
* automatic angle-bracketed link, e.g. <https://example.org> (used in footnote 5)
* by-reference link
* inline link
* by-reference footnote
* inline footnote
* header
* ordered list
* unordered list (*this* list is the example of that)
* emphasized text (bold, italics, and bold italics)
* code span
* code block
* table
* *and more...*
## View the Source
Here is the source code of the “main matter”^[A document often comprises front matter, main matter, and back matter.] of this article. This does not include the source code of the header, <abbr title="Table Of Contents">TOC</abbr>, News section, or anything below *this* sentence (other than the footnotes that are specified in the source code above this sentence).
If you are wondering how I display the raw unrendered source code of
part of this article inside this article (just above here), here’s the
story: I put the source code fragments of this article into a Hugo leaf bundle and then use my custom Hugo shortcode named
get-leaf-text
and Hugo’s built-in highlight shortcode
to get and highlight the “main matter”
For more related to Markdown, see Infinite Ink’s…
Hugo Shortcodes: How to Use Go Templates in Hugo Content Files
Hugo’s .RenderString
Method (featuring AsciiDoc admonitions in Markdown)
TGIH: Themeless & Gitless Introduction to the Hugo SSG (a Hugo tutorial👩🏫)
Hugo’s Markup Languages: AsciiDoc, HTML, Markdown,
Using a renderas
Shortcode to Compare Hugo’s Markup Languages (featuring inline footnotes)📊
🔗 Linkified Section Headings in Hugo-Generated Web Pages (featuring Markdown and AsciiDoc examples)
Many Infinite Ink articles, including this one, are evergreen and regularly updated.↩︎
As you can read in miek.nl/2016/march/05/mmark-syntax-document/, the 2016 version of the Mmark Markdown renderer supports abbreviations.↩︎
PHP Markdown Extra (which is also known as PHPME or Markdown Extra or MDExtra) is available on Tumblr and is the flavor of Markdown that I originally wrote this article in. As far as I can tell, it is currently the only Markdown renderer that supports abbreviations (with a Markdown syntax that is not raw HTML).↩︎
To learn about Goldmark, Pandoc, and other renderers that Hugo supports, see Infinite Ink’s Hugo’s Markup Languages: AsciiDoc, HTML, Markdown, Org-mode, Pandoc, & reStructuredText.↩︎
Markdown is a lightweight markup language that I wrote about in https://nancym.tumblr.com/post/43431761935/maybe-if-i-learn-markdown-ill-blog-more.↩︎
In a desktop web browser, an abbreviation is usually
rendered as a mouseover pop-up definition. In
HTML4, abbreviations are
specified using the abbr
or acronym
tag. In
HTML5, only the abbr
tag is used.↩︎
Footnotes are also known as endnotes.↩︎
A document often comprises front matter, main matter, and back matter.↩︎
@nm@mathstodon.xyz
or
#InfiniteInk
in it.