Markdown is a commonly used markup format used for blogs, documentation, and other longform content. It translates easily into HTML, and is easy for humans to read in its raw form.
We use Markdown heavily at Doctave (since our product supports it), and often found ourselves double-checking syntax. “How did you right-align a table column again?”. So, this is a reminder for our future selves.
In this post, we will go over Markdown’s core features and associated syntax. We will also mention some commonly found extensions to Markdown.
Basic Markdown features
First, let’s go through basic Markdown features supported by all parsers.
Headings
You can specify headings in the ATX
format, where the text of the heading is preceded by 1-6 #
characters,
corresponding to h1
to h6
headings.
Alternatively, you can use the
Setext-style
where you underline your heading with either =
for h1
, or -
for h2
headings.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// ATX "hash" style
# H1 heading
## H2 heading
### H3 heading
#### H4 heading
##### H5 heading
###### H6 heading
// Setext "underline" style
H1 heading
==========
H2 heading
----------
Emphasis
You can bold and italicise text by surrounding a string in one or two *
or
_
characters. One character for italics, two for bold.
1
**Bold text**. __This is also bold__.
Bold text. This is also bold.
1
*Italicised text*. _This is also italicised_.
Italicised text. This is also italicised.
Lists
Markdown supports unordered and ordered lists.
Unordered lists
You can use the *
, +
or -
characters to define unordered lists:
1
2
3
4
5
* Mary
* had
* A little lamb
Its fleece was white as snow
- Mary
- had
-
A little lamb
Its fleece was white as snow
-
⚠️ Note how the last line “Its fleece was white as snow” is interpreted as being part of the list item. As long as your indentation matches the start of the list item, you can include multiple paragraphs inside a list item.
Ordered lists
1
2
3
4
1. Mary
2. Had
3. A little
1. Lamb
- Mary
- Had
- A little
- Lamb
Links
I never remember which braces come first with Markdown links…
1
Here is a link to [Doctave](https://doctave.com).
Here is a link to Doctave.
Images
Images work like links, except you put an exclamation mark before the link text.
1
![A random image](https://picsum.photos/600/400)
Quotes
1
> It's true, because it's a quote
It’s true, because it’s a quote
Code
Markdown supports inline code as well as code blocks. You’ve seen plenty of examples already in this document.
Inline
1
Use `backticks for inline code snippets`.
Use backticks for inline code snippets
.
Block
Either use three backticks
1
2
3
```
For().your().code()
```
To achieve:
1
For().your().code()
Or indent your code with 4 spaces:
1
For().your().code()
For the same effect:
1
For().your().code()
Some providers will support syntax highlighting, in which case you can specify the language of the code example:
1
2
3
4
5
```ruby
def hello
puts "world"
end
```
Isn’t it pretty?
1
2
3
def hello
puts "world"
end
If you prefer, or your code example contains 3 backticks, you can replace
backticks with the ~
character.
1
2
3
~~~
Not with backticks
~~~
Gives you:
1
Not with backticks
HTML
You can include inline HTML in your Markdown document. Note that some services will disable this feature for security reasons.
1
<p style="transform: rotate(12deg); transform-origin: bottom left;">Askew</p>
Askew
Common extensions
These are some extensions that are commonly found in Markdown implementations that follow either the GitHub Flavored Markdown or CommonMark specs.
It’s best to check your Markdown library’s support for these features.
Strikethrough
1
The following should be ~~redacted~~
The following should be redacted
Task Lists
1
2
3
- [ ] This is a list of to-dos
- [x] This is a completed item
- [ ] This is an uncompleted item
- This is a list of to-dos
- This is a completed item
- This is an uncompleted item
Tables
Tables can be annoying to write by hand. However there are tools you can use that do the formatting for you.
Note in this example how the first row becomes the table heading. Also, the
second and third columns are center and right-aligned respectively. This is
achieved by using :
characters in the divider as shown below.
1
2
3
4
| This is a heading | Centered | This is right-aligned |
|--------------------------------|:--------:|-------------------------:|
| This is content for a columns | Hello | This is **bold** |
| You can have more rows | World | And more columns |
This is a heading | Centered | This is right-aligned |
---|---|---|
This is content for a columns | Hello | This is bold |
You can have more rows | World | And more columns |
Doctave is a docs platform designed for docs-as-code
Tired of wrangling open source tools and complex documentation deployments? Doctave makes deploying documentation sites with docs-as-code easier than ever.
Articles about documentation, technical writing, and Doctave into your inbox every month.