Sub topic 17
Escaping characters and using footnotes
This chapter assumes you can write headings, lists, links, and code spans in GitHub Flavored Markdown (GFM). You should also know how a table row is built. Here you will learn to show Markdown symbols as plain text and to add footnotes.
Why characters need escaping
Some characters have a meaning in Markdown. An asterisk starts emphasis, a hash starts a heading, and square brackets start a link. When you want the symbol itself, you have to tell the renderer to ignore its meaning.
Backslash escapes
Put a backslash before any ASCII punctuation character to make it literal. The backslash itself does not appear in the output.
\*not italic\*
\# Not a heading
1986\. A great year for the project.
Use \<name\> as a placeholder.The third line matters because "1986." at the start of a line would otherwise become a list item. The fourth line matters because GitHub treats <name> as an HTML tag and hides it.
Escaping inside code
Inside a code span or a fenced code block, backslashes are not special. Everything is shown exactly as written, so you rarely need to escape there. To show a backtick inside a code span, wrap the span in a longer run of backticks:
Run the `` `date` `` command.For a placeholder such as <name>, a code span is usually clearer than a backslash escape.
Pipes in tables
The | character separates table cells. A literal pipe in a cell needs a backslash, even inside a code span.
| Option | Values |
|:-------|:-------|
| `mode` | `fast \| safe` |Footnotes
A footnote puts a source or side note at the bottom of the page. Add a reference such as [^1] in the text. Then add a definition line that starts with the same label.
The parser follows the CommonMark spec.[^spec]
Output is cached between runs.[^cache]
[^spec]: Version 0.31 of the specification.
[^cache]: Delete the `.cache` folder to reset it.GitHub numbers footnotes in the order they are referenced, whatever the labels are. It adds a link on each footnote that jumps back to the reference. Definitions can sit anywhere in the file, but keeping them at the end is easier to maintain.
Common errors
| Symptom | Cause | Fix | Column |
|---|---|---|---|
| Text between angle brackets disappears | Treated as an HTML tag | Use a code span or `\<` | |
| A year becomes "1." in a list | Line starts with a number and a period | Write `1986\.` | |
| Table row has an extra column | Unescaped `\ | ` in a cell | Escape the pipe |
| Footnote shows as plain `[^1]` | No matching definition | Add a definition with the same label |
Exercise
A table cell should show the text a | b as code. What do you write in the cell, and why?
Show answer
Write a \| b inside backticks. A table parser splits cells on every unescaped pipe, even inside a code span, so the pipe needs a backslash. The rendered cell shows a | b.
Exercise
You wrote "[^note]" in a paragraph but see the literal text on the page. What is the most likely cause?
Show answer
The README has no definition line starting with "[^note]:". A footnote renders only when a reference and a definition share the same label.