Markdown Cheatsheet

Markdown Cheatsheet

十二月 06, 2001

注:原文摘自网上

Installation


This post uses hexo-renderer-markdown-it plugin as markdown processor, so please install it to achieve the effect.

installation
1
2
3
4
5
6
npm un hexo-renderer-marked --save
npm i hexo-renderer-markdown-it --save
npm i markdown-it-emoji --save
npm i markdown-it-mark --save
npm i markdown-it-deflist --save
npm i markdown-it-container --save

Configuration

Add following to _config.yml of your site.

_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
markdown:
render:
html: true
xhtmlOut: false
breaks: false
linkify: true
typographer: true
quotes: '“”‘’'
plugins:
- markdown-it-abbr
- markdown-it-footnote
- markdown-it-ins
- markdown-it-sub
- markdown-it-sup
- markdown-it-deflist
anchors:
level: 2
collisionSuffix: 'v'
permalink: false
permalinkClass: header-anchor
permalinkSymbol: " "
permalinkBefore: false

Usage


Headings

source code
1
2
3
4
5
6
# h1 Heading 8-)
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading

h1 Heading 8-)

h2 Heading

h3 Heading

h4 Heading

h5 Heading
h6 Heading

Horizontal Rules

source code
1
2
3
4
5
___

---

***



Typographic replacements

source code
1
2
3
4
5
6
7
(c) (C) (r) (R) (tm) (TM) (p) (P) +-

test.. test... test..... test?..... test!....

!!!!!! ???? ,, -- ---

"Smartypants, double quotes" and 'single quotes'

(c) (C) (r) (R) (tm) (TM) (p) (P) +-

test.. test… test….. test?….. test!….

!!!!!! ???? ,, – —

“Smartypants, double quotes” and ‘single quotes’

Emphasis

source code
1
2
3
4
5
6
7
8
9
**This is bold text**

__This is bold text__

*This is italic text*

_This is italic text_

~~Strikethrough~~

This is bold text

This is bold text

This is italic text

This is italic text

Strikethrough

Blockquotes

source code
1
2
3
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.

Blockquotes can also be nested…

…by using additional greater-than signs right next to each other…

…or with spaces between arrows.

Lists

Unordered

source code
1
2
3
4
5
6
7
+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!
  • Create a list by starting a line with +, -, or *
  • Sub-lists are made by indenting 2 spaces:
    • Marker character change forces new list start:
      • Ac tristique libero volutpat at
      • Facilisis in pretium nisl aliquet
      • Nulla volutpat aliquam velit
  • Very easy!

Ordered

source code
1
2
3
4
5
6
1. Lorem ipsum dolor sit amet
1. Indented list
1. Another level
2. Indent
2. Consectetur adipiscing elit
3. Integer molestie lorem at massa
  1. Lorem ipsum dolor sit amet
    1. Indented list
      1. Another level
    2. Indent
  2. Consectetur adipiscing elit
  3. Integer molestie lorem at massa
source code
1
2
1. You can use sequential numbers...
1. ...or keep all the numbers as `1.`
  1. You can use sequential numbers…
  2. …or keep all the numbers as 1.

Start numbering with offset:

source code
1
2
57. foo
1. bar
  1. foo
  2. bar

Code

source code
1
Inline `code`

Inline code

Indented code

source code
1
2
3
4
// Some comments
line 1 of code
line 2 of code
line 3 of code
// Some comments
line 1 of code
line 2 of code
line 3 of code

Block code “fences”

source code
1
2
3
```
Sample text here...
```
1
Sample text here...

Syntax highlighting

source code
1
2
3
4
5
6
7
``` js sample.js
var foo = function (bar) {
return bar++;
};

console.log(foo(5));
```

sample.js
1
2
3
4
5
var foo = function (bar) {
return bar++;
};

console.log(foo(5));

Tables

source code
1
2
3
4
5
| Option | Description |Description | Description | Description | 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. |
Option Description Description Description Description 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 aligned columns

source code
1
2
3
4
5
| 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. |
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.
source code
1
[link text](http://dev.nodeca.com)

link text

source code
1
[link with title](http://nodeca.github.io/pica/demo/ "title text!")

link with title

source code
1
Autoconverted link https://github.com/nodeca/pica (enabled linkify)

Autoconverted link https://github.com/nodeca/pica (enabled linkify)

Images

source code
1
2
![Minion](https://octodex.github.com/images/minion.png)
![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat")

Minion
Stormtroopocat

Like links, Images also have a footnote style syntax

source code
1
2
3
4
5
![Alt text][id]

With a reference later in the document defining the URL location:

[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"

Alt text

With a reference later in the document defining the URL location:

Plugins

The killer feature of markdown-it is very effective support of
syntax plugins. The sample configuration snippet

Emojies

source code
1
2
3
Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:

Shortcuts (emoticons): :-) :-( 8-) ;)

Classic markup: :wink: :crush: :cry: :tear: :laughing: :yum:

Shortcuts (emoticons): :-) :-( 8-) ;)

Subscript / Superscript

source code
1
2
3
Superscript: 19^th^

Subscript: H~2~O

Superscript: 19^th^

Subscript: H~2~O

\

source code
1
++Inserted text++

++Inserted text++

\

source code
1
==Marked text==

==Marked text==

Footnotes

source code
1
2
3
4
5
6
7
8
9
10
11
12
13
Footnote 1 link[^first].

Footnote 2 link[^second].

Inline footnote^[Text of inline footnote] definition.

Duplicated footnote reference[^second].

[^first]: Footnote **can have markup**

and multiple paragraphs.

[^second]: Footnote text.

Footnote 1 link[^first].

Footnote 2 link[^second].

Inline footnote^[Text of inline footnote] definition.

Duplicated footnote reference[^second].

[^first]: Footnote can have markup

and multiple paragraphs.

[^second]: Footnote text.

Definition lists

source code
1
2
3
Term 1
: Definition 1
with lazy continuation.

Term 1
: Definition 1
with lazy continuation.

source code
1
2
3
4
5
6
Term 2 with *inline markup*
: Definition 2

{ some code, part of Definition 2 }

Third paragraph of definition 2.

Term 2 with inline markup
: Definition 2

    { some code, part of Definition 2 }

Third paragraph of definition 2.

Compact style:

source code
1
2
3
4
5
6
Term 1
~ Definition 1

Term 2
~ Definition 2a
~ Definition 2b

Term 1
~ Definition 1

Term 2
~ Definition 2a
~ Definition 2b

Abbreviations

source code
1
2
3
4
5
This is HTML abbreviation example.

It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on.

*[HTML]: Hyper Text Markup Language

This is HTML abbreviation example.

It converts “HTML”, but keep intact partial entries like “xxxHTMLyyy” and so on.

*[HTML]: Hyper Text Markup Language

Custom containers

::: warning
here be dragons
:::

Hexo Built-in Tags

Blockquote with author

source code
1
2
3
{% blockquote David Levithan, Wide Awake %}
Do not just seek happiness for yourself. Seek happiness for all. Through kindness. Through mercy.
{% endblockquote %}

Do not just seek happiness for yourself. Seek happiness for all. Through kindness. Through mercy.

David LevithanWide Awake

Blockquote for twitter

source code
1
2
3
{% blockquote @DevDocs https://twitter.com/devdocs/status/356095192085962752 %}
NEW: DevDocs now comes with syntax highlighting. http://devdocs.io
{% endblockquote %}

NEW: DevDocs now comes with syntax highlighting. http://devdocs.io

source code
1
2
3
{% blockquote Seth Godin http://sethgodin.typepad.com/seths_blog/2009/07/welcome-to-island-marketing.html Welcome to Island Marketing %}
Every interaction is both precious and an opportunity to delight.
{% endblockquote %}

Every interaction is both precious and an opportunity to delight.

Pull Quotes

source code
1
2
3
{% pullquote %}
content
{% endpullquote %}

content

jsFiddle

source code
1
{% jsfiddle o2gxgz9r default light %}

Gist

source code
1
{% gist b6365e79be6052e7531e7ba6ea8caf23 'Sample gist' %}

iFrame

source code
1
{% iframe https://leewp14.github.io %}
source code
1
{% link Google https://www.google.com default Google %}
Google

Youtube

source code
1
{% youtube sCI4bUHoTVY %}

Tags provided by third party