Markdown
Markdown is “a plain text format for writing structured documents, based on formatting conventions from email and usenet” – CommonMark
Sites like GitHub and Stackoverflow have popularized the use markdown as a plain-text alternative to traditional text editors, for writing things like documentation and comments. The following markdown features are defined by the CommonMark standard, and are generally supported by all markdown parsers and editors.
# Headings
Headings from h1
through h6
are constructed with a #
for each level:
|
|
Renders to this HTML:
|
|
Which looks like this in the browser:
# h1 Heading
# h2 Heading
# h3 Heading
# h4 Heading
# h5 Heading
# h6 Heading
A note about “Setext” Headings
Note that this document only describes ATX headings, as it is the preferred syntax for writing headings. However, the CommonMark specification also describes Setext headings, a heading format that is denoted by a line of dashes or equal signes following the heading. It’s recommended by the author of this guide that you use only ATX headings, as they are easier to write and read in text editors, and are less likeley to conflict with other syntaxes and demarcations from language extensions.
# Paragraphs
Body copy written as normal plain-text will be wrapped with <p></p>
tags in the rendered HTML.
So this:
|
|
Renders to this HTML:
|
|
# Breaks
You can use multiple consecutive newline characters (\n
) to create extra spacing between sections in a markdown document. However, if you need to ensure that extra newlines are not collapsed, you can use as many HTML <br>
elements as you want.
# Horizontal Rule
The HTML <hr>
element is for creating a “thematic break” between paragraph-level elements. In markdown, you can use of the following for this purpose:
___
: three consecutive underscores---
: three consecutive dashes***
: three consecutive asterisks
Renders to:
# Emphasis
# Bold
For emphasizing a snippet of text with a heavier font-weight.
The following snippet of text is rendered as bold text.
|
|
renders to:
rendered as bold text
and this HTML
|
|
# Italics
For emphasizing a snippet of text with italics.
The following snippet of text is rendered as italicized text.
|
|
renders to:
rendered as italicized text
and this HTML:
|
|
# Blockquotes
Used for defining a section of quoting text from another source, within your document.
To create a blockquote, use >
before any text you want to quote.
|
|
Renders to:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.
And the generated HTML from a markdown parser might look something like this:
|
|
Blockquotes can also be nested:
|
|
Renders to:
Donec massa lacus, ultricies a ullamcorper in, fermentum sed augue. Nunc augue augue, aliquam non hendrerit ac, commodo vel nisi.
Sed adipiscing elit vitae augue consectetur a gravida nunc vehicula. Donec auctor odio non est accumsan facilisis. Aliquam id turpis in dolor tincidunt mollis ac eu diam.
Donec massa lacus, ultricies a ullamcorper in, fermentum sed augue. Nunc augue augue, aliquam non hendrerit ac, commodo vel nisi.
# Lists
# Unordered Lists
A list of items in which the order of the items does not explicitly matter.
You may use any of the following symbols to denote bullets for each list item:
|
|
For example
|
|
Renders to:
- Lorem ipsum dolor sit amet
- Consectetur adipiscing elit
- Integer molestie lorem at massa
- Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
- Phasellus iaculis neque
- Purus sodales ultricies
- Vestibulum laoreet porttitor sem
- Ac tristique libero volutpat at
- Faucibus porta lacus fringilla vel
- Aenean sit amet erat nunc
- Eget porttitor lorem
And this HTML
|
|
# Ordered Lists
A list of items in which the order of items does explicitly matter.
|
|
Renders to:
- Lorem ipsum dolor sit amet
- Consectetur adipiscing elit
- Integer molestie lorem at massa
- Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
- Faucibus porta lacus fringilla vel
- Aenean sit amet erat nunc
- Eget porttitor lorem
And this HTML:
|
|
# Time-saving Tip!
Sometimes lists change, and when they do it’s a pain to re-order all of the numbers. Markdown solves this problem by allowing you to simply use 1.
before each item in the list.
For example:
|
|
Automatically re-numbers the items and renders to:
- Lorem ipsum dolor sit amet
- Consectetur adipiscing elit
- Integer molestie lorem at massa
- Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
- Faucibus porta lacus fringilla vel
- Aenean sit amet erat nunc
- Eget porttitor lorem
# Code
# Inline code
Wrap inline snippets of code with a single backtick: `.
For example, to show <div></div>
inline with other text, just wrap it in backticks.
|
|
# “Fenced” code block
Three consecutive backticks, referred to as “code fences”, are used to denote multiple lines of code: ```.
For example, this:
Renders to something like this in HTML:
|
|
And appears like this when viewed in a browser:
|
|
# Indented code
You may also indent several lines of code by at least four spaces, but this is not recommended as it is harder to read, harder to maintain, and doesn’t support syntax highlighting.
Example:
|
|
// Some comments
line 1 of code
line 2 of code
line 3 of code
# Syntax highlighting
Various markdown parsers, such as remarkable, support syntax highlighting with fenced code blocks. To activate the correct styling for the language inside the code block, simply add the file extension of the language you want to use directly after the first code “fence”: ```js, and syntax highlighting will automatically be applied in the rendered HTML (if supported by the parser). For example, to apply syntax highlighting to JavaScript code:
Which renders to:
|
|
And this complicated HTML is an example of what might be generated by the markdown parser, when syntax highlighting is applied by a library like highlight.js:
|
|
# Links
# Autolinks
Autolinks are absolute URIs and email addresses inside <
and >
. They are parsed as links, where the URI or email address itself is used as the link’s label.
|
|
Renders to:
URIs or email addresses that are not wrapped in angle brackets are not recognized as valid autolinks by markdown parsers.
# Inline links
|
|
Renders to (hover over the link, there is no tooltip):
HTML:
|
|
# Link titles
|
|
Renders to (hover over the link, there should be a tooltip):
HTML:
|
|
# Named Anchors
Named anchors enable you to jump to the specified anchor point on the same page.
For example, the following “chapter” links:
|
|
…will jump to these sections:
|
|
Anchor placement
Note that placement of achors is arbitrary, you can put them anywhere you want, not just in headings. This makes adding cross-references easy when writing markdown.
# Images
Images have a similar syntax to links but include a preceding exclamation point.
|
|
or
|
|
Like links, Images also have a footnote style syntax
|
|
With a reference later in the document defining the URL location:
|
|
# Raw HTML
Any text between <
and >
that looks like an HTML tag will be parsed as a raw HTML tag and rendered to HTML without escaping.
(Note that markdown parsers do not attempt to validate your HTML).
Example:
|
|
Renders to:
Visit Jon Schlinkert’s GitHub Profile.
# Escaping with backslashes
Any ASCII punctuation character may be escaped using a single backslash.
Example:
|
|
Renders to:
*this is not italic*
# Non-standard features
The following markdown features are not defined by the CommonMark specification, but they are commonly supported by markdown parsers and editors, as well as sites like GitHub and GitLab.
# Strikethrough
In GitHub Flavored Markdown (GFM) you can do strickthroughs.
|
|
Which renders to:
Strike through this text.
# Todo List
|
|
Renders to:
- Lorem ipsum dolor sit amet
- Consectetur adipiscing elit
- Integer molestie lorem at massa
Links in todo lists
|
|
Renders to:
# Tables
Tables are created by adding pipes as dividers between each cell, and by adding a line of dashes (also separated by bars) beneath the header (this line of dashes is required).
- pipes do not need to be vertically aligned.
- pipes on the left and right sides of the table are sometimes optional
- three or more dashes must be used for each cell in the separator row (between the table header and body)
- the left and right pipes are optional with some markdown parsers
Example:
|
|
Renders to:
Option | Description |
---|---|
data | path to data files to supply the data that will be passed into templates. |
engine | engine to be used for processing templates. Handlebars is the default. |
ext | extension to be used for dest files. |
And this HTML:
|
|
# Aligning cells
Center text in a column
To center the text in a column, add a colon to the middle of the dashes in the row beneath the header.
|
|
| Option | Description | | -:- | -:- | | data | path to data files to supply the data that will be passed into templates. | | engine | engine to be used for processing templates. Handlebars is the default. | | ext | extension to be used for dest files. |
Right-align the text in a column
To right-align the text in a column, add a colon to the middle of the dashes in the row beneath the header.
|
|
Renders to:
Option | Description |
---|---|
data | path to data files to supply the data that will be passed into templates. |
engine | engine to be used for processing templates. Handlebars is the default. |
ext | extension to be used for dest files. |
# Footnotes
Markdown footnotes are not officially suppored by the CommonMark specification. However, the feature is supported by remarkable and other markdown parsers, and it’s very useful when available.
Markdown footnotes are denoted by an opening square bracket, followed by a caret, followed by a number and a closing square bracket: [^1]
.
|
|
The accompanying text for the footnote can be added elsewhere in the document using the following syntax:
|
|
When rendered to HTML, footnotes are “stacked” by the markdown parser at the bottom of the file, in the order in which the footnotes were defined.
# Inline footnotes
Some markdown parsers like
Remarkable also support inline footnotes. Inline footnotes are written using the following syntax: [^2 "This is an inline footnote"]
.