摘要
本文介绍Markdown的语法,明确如何使用各语法编写Markdown文档。
目录
提示:以下是本篇文章正文内容,下面命令及案例可供参考
一、基本语法
1. 标题
- 创建标题,在单词或短语前添加井号(#);
#
的数量便是标题的级别。 - 用一个空格在
#
和标题之间进行分隔。
Do this | Do not do this |
---|---|
# Here 's a heading | #Here’s a heading |
2. 段落
- 不用空格(space)和制表符(Tab)缩进段落;空格使用
 
,制表符使用&emsp
。
Do this | Do not do this |
---|---|
Do not put space and tabs in front of your paragraphs. Keep lines left-alighed like this. | Do not put space and tabs in front of your paragraphs. Keep lines left-alighed like this. |
- 使用空白行将一行或多行文本进行分隔。
3. 格式
- 使用回车键或HTML中的
<br>
- 空格符: 
- Tab符:&emsp
- 转义字符:
\
4. 强调
- 使用
*
设为斜体
- 在需要设为斜体 的单词或短语的前后各添加一个型号
- 格式:
*斜体*
:斜体
- 使用
**
进行加粗
- 在需要加粗部分的单词或短语的前后各添加加两个星号
- 格式:
**加粗**
:加粗
- 使用
***
设为斜体并加粗
- 在需要加粗部分的单词或短语的前后各添加加三个星号
- 格式:
***斜体并加粗***
:斜体并加粗
5. 引用
- 使用
>
进行引用表示。
6. 分隔线
- 在单独一行使用三个或多个星号(***)、破折号(—)、下划线(___),且不能包含其他内容。
格式:***
7. 链接
-
第一种写法:使用尖括号表示链接地址。
格式:<超链接地址>
https://www.csdn.net -
第二种写法:链接文本放在中括号内,链接地址放在括号内,链接title可写可不写。
格式: [超链接显示名](超链接地址 "超链接title")
- 第三种写法:引用类型链接;引用类型的链接的第一部分使用两组括号进行格式设置。第一组方括号包围应显示为链接的文本。第二组括号显示了一个标签,该标签用于指向您存储在文档其他位置的链接,即第二组“ [?]:???” 可以编写在文章中其他位置。
格式:[CSDN][1] [1]: https://www.csdn.net
- 第四种写法:使用星号,使链接带格式(星号和反引号前后需要用空格与其他文本分隔开)。格式:
**[CSDN](https://www.csdn.net) **
、*[CSDN](https://www.csdn.net) *
这是一个 CSDN 上的文章。
这是一个 CSDN 上的文章。
8. 列表
8.1 无序列表
格式:
- First item
- Second item
- Third item
Markdown中显示:
- First item
- Second item
- Second 1
- Second 2
- Second 3
- Third item
8.2 有序列表
格式:
1. First item
2. Second item
3. Third item
Markdown中显示:
- First item
- Second item
- Third item
二、扩展语法
1. 代码块
-
在代码块的前后各添加三个反引号(```),形成围栏代码块;在受防护的代码块之前的反引号旁边指定一种语言。
格式:```cpp #include <iostream> using namespace std; int main(){   cout << "hello world!" << endl;   retrun 0; } ```
Markdown中显示:
#include <iostream>
using namespace std;
int main(void){
cout << "hello world!" << endl;
retrun 0;
}
- 常用的代码块语言:
- Javascript:js
- C:c
- C++:cpp
- Python:python
- HTML:html
- Bash:bash
- Shell:shell
- PowerShell:ps
- JSON:json
2. 表格
- 使用三个或多个连字符(—)创建每列标题,并使用管道(|)分隔每列。
- 表格中内容的对齐方式。
|:---|
表示左对齐;|:---:|
表示居中对齐;|---:|
表示右对齐。
| 第一列 | 第二列 | 第三列|
|:---|:---:|---:|
| 左对齐 | 居中对齐 | 右对齐 |
Markdown中显示:
第一列 | 第二列 | 第三列 |
---|---|---|
左对齐 | 居中对齐 | 右对齐 |
3. 定义列表
格式:
First Term
: This is the definition of the first term.
Second Term
: This is one definition of the second term.
: This is another definition of the second term.
Markdown中显示:
-
First Term
- This is the definition of the first term. Second Term
- This is one definition of the second term.
- This is another definition of the second term.
4. 删除线
格式:
~~文本~~
Markdown中显示:
文本
5. 任务列表
格式:
- [x] The first element
- [ ] The second element
- [ ] The third element
Markdown中显示:
- Write the press release
- Update the website
- Contact the media
6. 脚注
格式:
Here's a sentence with a footnote. [^1]
[^1]: This is the footnote.
Markdown中显示:
Here’s a sentence with a footnote. 1
三、参考文献
1 Markdown官方教程
[2] Matt Cone. 《The Markdown Guide》. 2020.6
This is the footnote. ↩︎