因为目前准备写博客,所以不可避免就要使用markdown语言写文章,所以这篇文章将对Markdown的基本语法进行介绍,方便以后查阅。

Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档。Markdown 编写的文档可以导出 HTML 、Word、图像、PDF、Epub 等多种格式的文档。目前常用的一些编辑器包括typora和VS Code以及vim等,目前我所使用的是VS code,使用VS Code需要安装 Markdown All in One 或 Markdown Preview Enhanced 插件从而可以进行预览。

本文章参考了Github上的Markdown Cheatsheet 以及简书上的 Markdown 语法小指南

分级标题

# H1
## H2
### H3
#### H4
##### H5
###### H6

也可使用===表示一级标题,使用---表示二级标题

Alt-H1
======

Alt-H2
------

H1

H2

H3

H4

H5
H6

也可使用===表示一级标题,使用—表示二级标题

Alt-H1

Alt-H2

文字样式

文字强调

*Italics* or _Italics_ 
**Bold** or __Bold__ 
***Bold Italics*** or ___Bold Italics___ 
~~Delete~~

Italics or Italics Bold or Bold Bold Italics or Bold Italics Delete

文字上下标(superscript and subscript)

这是^上标文字^
这是~下标文字~

这是^上标文字^ 这是~下标文字~

字体下划线

<u>Underline</u>

Underline

字体背景高亮

==Highlight==

==Highlight==

列表

有序列表

==数字不能省略但可无序==,点号之后的空格不能少。建立多级列表时,每个子级别都要比上个级别前面多打2个以上空格。

1. Item-1
 1.1. Item-1-1
    1.1.1. Item-1-1-1
      1.1.1.1. Item-1-1-1-1
  1.2. Item-1-2
2. Item-2
6. Item-3
  1. Item-1 1.1. Item-1-1 1.1.1. Item-1-1-1 1.1.1.1. Item-1-1-1-1 1.2. Item-1-2
  2. Item-2
  3. Item-3

无序列表

符号之后的空格不能少,-、+、*效果一样,在嵌套列表中可以循环使用。

- Item-1
  * Item-1-1
    + Item-1-1-1
      * Item-1-1-1-1
  * Item-1-2
+ Item-2
* Item-3
  • Item-1
    • Item-1-1
      • Item-1-1-1
        • Item-1-1-1-1
    • Item-1-2
  • Item-2
  • Item-3

有两种添加链接的方式,分别为内联(inline)和引用(reference)

内联(inline)

[I'm an inline-style link](https://www.google.com)

[I'm an inline-style link with title](https://www.google.com "Google's Homepage")

I’m an inline-style link

I’m an inline-style link with title

引用(reference)

引用(Reference):一般应用于多个不同位置使用相同链接。通常分为两个部分:

调用部分格式为:[链接文本][ref]

定义部分可以出现在文本中的其他位置,格式为:[ref]: http://some/link/address (可选的标题)。

This is [an example][ref] reference-style link.
[ref]: http://slashdot.org "Optional Title Here"

This is [an example][ref] reference-style link. [ref]: http://slashdot.org “Optional Title Here”

自动创建链接

使用尖括号<>,可以为输入的URL或者邮箱自动创建链接,如https://www.baidu.com。

<https://www.baidu.com>

https://www.baidu.com

添加图片(Images)

添加图片的使用方法基本上和链接类似,只是在中括号前加叹号!,即![alt text](URL "Image Title")

内联法: 
![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")

引用法: 
![alt text][logo]

[logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"

内联法:

alt text
Logo Title Text 1

引用法:

alt text
Logo Title Text 2

文字引用(Blockquotes)

使用>表示文字引用。可以多级引用。

> Quote 1
> > Quote 2
> > > Quote 3

Quote 1

Quote 2

Quote 3

想在列表项里面使用区块引用,定界符>必须得缩进:

* Item
  > Quote 1
  > Quote 2
  • Item

    Quote 1 Quote 2

转义字符(Backslash Escapes)

Markdown 可以利用反斜杠\来插入一些在语法中有其它意义的符号,例如:如果想要用星号加在文字旁边的方式来做出强调效果,可以在星号的前面加上反斜杠:

\*literal asterisks\*

*literal asterisks*

代码块引用(Fenced Code Blocks)

var s = "JavaScript syntax highlighting";
alert(s);
s = "Python syntax highlighting"
print s
No language indicated, so no syntax highlighting. 
But let's throw in a <b>tag</b>.

注:代码缩进请使用四个空格,不要使用 Tab。

表格(Tables)

| Tables | Are | Cool  |
| ------ |:---:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

|-: 之间的多余空格会被忽略,不影响布局。 默认标题栏居中对齐,内容居左对齐。 -: 表示内容和标题栏居右对齐,:- 表示内容和标题栏居左对齐,:-: 表示内容和标题栏居中对齐。 内容和 | 之间的多余空格会被忽略,每行第一个 | 和最后一个|可以省略,- 的数量至少有一个。

分隔线

在一行中使用三个或三个以上的 *-_ 可以添加分隔线,中间插入空格,但是不能有其他字符。下面每种写法都可以建立分隔线:

* * *

***

*****

- - -

------

添加脚注(Footnotes)

脚注是在需要标记脚注文字的后面增加一个方括号,方括号中的内容必须以 ^ 开头,再接着是数字、字符串标记:

Footnotes[^1] have a label[^label] and a definition[^!DEF].

接着,在文件的任意地方,可以把这个脚注的内容定义出来。脚注内容定义的形式就是前面引用脚注的内容,接着一个冒号,再接着一个以上的空格或制表符,最后是脚注定义的内容:

[^1]: This is a footnote
[^label]: A footnote on "label"
[^!DEF]: The definition of a footnote.

Footnotes1 have a label2 and a definition3.

脚注定义的内容可以包含多行、段落、代码区块、区块引用和大多数其他 markdown 格式的内容。对于多行的内容只需要简单缩进至少4个空格。

[^1]: The first paragraph of the definition.

        Paragraph two of the definition.

        > A blockquote with
        > multiple lines.

                a code block

        A final paragraph.

默认情况下,脚注内容位于生成的 HTML 文档末尾。

目录(Table of Contents)

在需要目录出现的地方放置一个标记,这样会自动生成一个嵌套的包含所有标题的列表。默认的标记是 [TOC]

[TOC]

  1. This is a footnote ↩︎

  2. A footnote on “label” ↩︎

  3. The definition of a footnote. ↩︎