Markdown Reference
Kip Landergren
(Updated: )
My cheat sheet for Markdown covering common authoring examples and documentation links.
Contents#
- markdown-study
-
Frequently Asked Questions (FAQs)
- Why are they called “atx-style” headers?
- How do you add a caption to a table?
- What are the supported highlighter values?
- What should REPLs like irb, psql, or sqlite use as their highlighter?
- What should shell commands—including the prompt—use as a code fence info string?
- What should shell commands—excluding the prompt—use as a code fence info string?
- Do angle brackets need to be escaped?
- Do ampersands need to be escaped?
- Wishlist for Markdown
- Resources
- Terminology
markdown-study#
README.md#
# markdown-study
Personal study area for [GitHub-flavored markdown](https://github.github.com/gfm/)
code.md#
You can specify `inline code` or:
```
block level code
```
and, for GitHub, specify the [language](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml):
```ruby
[1,2,3].map {|x| x * x }
```
to code fence code that itself has code fences:
````markdown
```ruby
puts "using more backticks than the contained works"
```
````
~~~markdown
```ruby
puts "using different delimiters like tildes also works"
```
~~~
headings.md#
# top level heading
typically h1 equivalent
## second level heading
typically h2 equivalent
### third level heading
typically h3 equivalent
links.md#
## HREFs
[link text](https://example.com)
## Anchor Links
[link to heading foo below](#Foo)
Difficulties:
* determining correct fragment (e.g. headings with complex characters)
* keeping up to date if heading title changes
### Foo
## Full Reference Links
Let’s imagine you want to make multiple references to
[a](https://github.com/klandergren/jekyll-last-commit)
[cool](https://github.com/klandergren/jekyll-last-commit)
[project](https://github.com/klandergren/jekyll-last-commit).
An alternative syntax is:
Let’s imagine you want to make multiple references to [a](jekyll-last-commit)
[cool](jekyll-last-commit) [project](jekyll-last-commit).
[jekyll-last-commit]: https://github.com/klandergren/jekyll-last-commit
Where the reference above (`[jekyll-last-commit]:
https://github.com/klandergren/jekyll-last-commit`) will be removed by the
markdown renderer.
This allows:
* more readable diffs
* more readable markdown
* single location update of links
lists.md#
## Unordered Lists
To add an item to an unordered list:
* indent zero spaces
* followed by a single:
* asterisk (`*`)
* dash (`-`)
* plus (`+`)
* followed by a single space
* followed by text
Sublist items are indented sufficient to align with the beginning content of the parent (typically an additional two spaces).
All of the following are equivalent.
preferred:
* Item A
* Item B
* Item C
* C Child 1
* C Child 2
alternatives:
- Item A
- Item B
- Item C
- C Child 1
- C Child 2
+ Item A
+ Item B
+ Item C
+ C Child 1
+ C Child 2
## Ordered Lists
To add an item to an ordered list:
* indent zero spaces
* followed by a single digit
* followed by a period
* followed by a single space
* followed by text
Sublist items are indented sufficient to align with the beginning content of the parent (typically an additional three spaces, but more if you use multi-digit numbers).
Preferred due to ease of reordering items:
1. item 1
1. item 2
1. item 3
1. item 1 of group 3
alternative:
1. item 1
2. item 2
3. item 3
1. item 1 of group three
gotcha: this still renders as 1 2 3:
1. item 1
3. item 3
2. item 2
gotcha: this isn’t a sublist because whitespace doesn’t align with the parent’s content’s start
1. item 1
1. item 2
1. item 3
1. item 1 of group 3
tables.md#
# per column alignment
| left | center | right | default (left aligned) |
|:------------|:-----------:|------------:|------------------------|
| lorem | lorem | lorem | lorem |
| lorem ipsum | lorem ipsum | lorem ipsum | lorem ipsum |
(afaik: no way to apply alignment per cell)
text.md#
## Emphasis
| | |
|-------|----------------|
| _foo_ | `<em>foo</em>` |
| *foo* | `<em>foo</em>` |
## Strong
| | |
|---------|------------------------|
| __foo__ | `<strong>foo</strong>` |
| **foo** | `<strong>foo</strong>` |
## Strikethrough
| | |
|---------|------------------|
| ~~foo~~ | `<del>foo</del>` |
## Blockquote
> this text is blockquoted
## Embedded HTML
The menu showed the option <samp>COMMAND</samp>.
## URLs
* [the display text](https://example.com)
* https://example.com
## Emails
<jdoe@example.com>
Frequently Asked Questions (FAQs)#
Why are they called “atx-style” headers?#
In reference to Aaron Swartz’ atx format.
atx-style:
# h1
## h2
setext-style:
h1
==
h2
--
Further reading:
How do you add a caption to a table?#
Captions are not supported.
What are the supported highlighter values?#
Depends on your syntax highlighter plug-in. I use alecthomas/chroma whose README.md lists their supported languages.
What should REPLs like irb, psql, or sqlite use as their highlighter?#
Personal preference: text
Consider the following, using console:
% sudo -u postgres psql --host /path/to/sockets --port 15432 --dbname organizer
psql (16.4)
Type "help" for help.
Cannot read termcap database;
using dumb terminal settings.
organizer=# select true;
?column?
----------
t
(1 row)
vs text:
% sudo -u postgres psql --host /path/to/sockets --port 15432 --dbname organizer
psql (16.4)
Type "help" for help.
Cannot read termcap database;
using dumb terminal settings.
organizer=# select true;
?column?
----------
t
(1 row)
What should shell commands—including the prompt—use as a code fence info string? #
Personal preference: text
Consider the following, using console:
% cd path/to/my/lib
Chroma highlights the prompt (good) and cd (questionable). I haven’t looked into seeing what rules are for non-prompt output but I prefer to have no ambiguity. Same example using text with no highlighting:
% cd path/to/my-gem
What should shell commands—excluding the prompt—use as a code fence info string?#
Personal preference: text
Consider the following, using shell:
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mov
Chroma treats the argument strings format=duration and csv=p=0 as variable assignments and highlights them. I find this misleading and distracting from the command.
Therefore I prefer using text with no highlighting:
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mov
Do angle brackets need to be escaped?#
When they wouldn’t be otherwise interpreted as an HTML element? No:
If a < b then do c.
Inside backticks? No:
`<div>` is my favorite HTML element.
Escape brackets when they would otherwise be interpreted as HTML:
\<div\> is my favorite HTML element.
<div> is my favorite HTML element.
Do ampersands need to be escaped?#
No.
Wishlist for Markdown#
- better nested content wrapping (without using a
<div>). example:
## heading a
heading a content
### heading b
heading b content
heading a content that resumes after the heading b digression
- special characters for
<samp>and<kbd>. maybe:
| =content= | wrapped in <samp> |
| +content+ | wrapped in <kbd> |
- a language highlighter for shell commands and one-liners. I don’t actually know what I want this to do though (maybe highlight the commands in separate colors? or highlight operators? idk).
Resources#
- CommonMark - A strongly defined, highly compatible specification of Markdown
- GitHub Flavored Markdown (gfm)
- Markdown Wikipedia Page
- Markdown: Syntax
- Extended Syntax
Terminology#
- code fence#(term code fence)
- fenced code block#(term fenced code block)
- 1.
An opening code fence, a content block, and closing code fence.
- info string#(term info string)(term highlighter)(term language)(term language identifier)
- 1.
The text directly after the opening code fence. Often the language of the text contained by the fenced code block.
Example:
ruby, below:```rubyAlso: highlighter, language, language identifier
Note: The CommonMark spec uses “info string”.