- 编程
Markdown基本语法
- 2024-11-1 15:14:54 @
Markdown基本语法
Markdown是一种轻量级标记语言,排版语法简洁,让人们更多地关注内容本身而非排版。它使用易读易写的纯文本格式编写文档,可与HTML混编,可导出 HTML、PDF 以及本身的 .md 格式的文件。因简洁、高效、易读、易写,Markdown被大量使用,如Github、Wikipedia、简书等。
Markdown标题语法
要创建标题,请在单词或短语前面添加井号 (#
) 。#
的数量代表了标题的级别。例如,添加三个 #
表示创建一个三级标题 (<h3>
) (例如:### My Header
)。
# 一级标题
## 二级标题
### 三级标题
#### 四级标题
##### 五级标题
###### 六级标题
Markdown段落语法
要创建段落,请使用空白行将一行或多行文本进行分隔。
要用空格(spaces)或制表符( tabs)缩进段落。
在一行的末尾添加两个或多个空格,然后按回车键,即可创建一个换行(<br>
)。
Markdown强调语法
粗体
要加粗文本,请在单词或短语的前后各添加两个星号(asterisks)或下划线(underscores)。如需加粗一个单词或短语的中间部分用以表示强调的话,请在要加粗部分的两侧各添加两个星号(asterisks)。
Markdown: **bold text**
或者 __bold text__
预期效果: bold text
斜体
要用斜体显示文本,请在单词或短语前后添加一个星号(asterisk)或下划线(underscore)。要斜体突出单词的中间部分,请在字母前后各添加一个星号,中间不要带空格。
Markdown: *Italic*
或者 _Italic_
预期效果: Italic
粗斜体
要同时用粗体和斜体突出显示文本,请在单词或短语的前后各添加三个星号或下划线。要加粗并用斜体显示单词或短语的中间部分,请在要突出显示的部分前后各添加三个星号,中间不要带空格。
Markdown: ***bold italic***
**_bold italic_**
**_bold italic_**
__*bold italic*__
___bold italic___
预期效果: bold italic
Markdown引用语法
要创建块引用,请在段落前添加一个 >
符号。
Markdown
> Dorothy followed her through many of the beautiful rooms in her castle.
预期效果
Dorothy followed her through many of the beautiful rooms in her castle.
块引用可以包含多个段落。为段落之间的空白行添加一个 >
符号。
Markdown
> Dorothy followed her through many of the beautiful rooms in her castle.
>
> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
预期效果
Dorothy followed her through many of the beautiful rooms in her castle.
The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
Markdown列表语法
有序列表
要创建有序列表,请在每个列表项前添加数字并紧跟一个英文句点。数字不必按数学顺序排列,但是列表应当以数字 1 起始。
Markdown:
1. Frist 2. Second 3. Third |
1. First 1. Second 1. Third |
1. First 8. Second 7. Third |
1. First 2. Second 1. First 2. Second |
---|
预期效果
有序列表
1. First 2. Second 3. Third
嵌套使用
1. First 2. Second 1. First 2. Second
无序列表
要创建无序列表,请在每个列表项前面添加破折号 (-)、星号 (*) 或加号 (+) 。缩进一个或多个列表项可创建嵌套列表。
Markdown
- Frist - Second - Thrid |
+ First + Second + Thrid |
* First * Second * Third |
- First - Second - First - Second |
---|
预期效果
无序列表
First
Second
Third
嵌套使用
First
Second
First
Second
在列表中添加其他元素
要在保留列表连续性的同时在列表中添加另一种元素,请将该元素缩进四个空格或一个制表符,如下例所示:
段落
Markdown
* This is the first list item.
* Here's the second list item.
I need to add another paragraph below the second list item.
* And here's the third list item.
预期效果
-
This is the first list item.
-
Here's the second list item.
I need to add another paragraph below the second list item.
-
And here's the third list item.
引用
Markdown
* This is the first list item.
* Here's the second list item.
> A blockquote would look great below the second list item.
* And here's the third list item.
预期效果
-
This is the first list item.
-
Here's the second list item.
A blockquote would look great below the second list item.
-
And here's the third list item.
代码块
代码块通常采用四个空格或一个制表符缩进。当它们被放在列表中时,请将它们缩进八个空格或两个制表符。
Markdown
1. Open the file.
2. Find the following code block on line 21:
<html>
<head>
<title>Test</title>
</head>
3. Update the title to match the name of your website.
预期效果
-
Open the file.
-
Find the following code block on line 21:
<html> <head> <title>Test</title> </head>
-
Update the title to match the name of your website.
Markdown代码语法
要将单词或短语表示为代码,请将其包裹在反引号 (` ) 中。
Markdown
Use `code` in your Markdown file.
预期效果
Use code
in your Markdown file.
代码块
要创建代码块,请将代码块的每一行缩进至少四个空格或一个制表符。
Markdown
<html>
<head>
</head>
</html>
预期效果
<html>
<head>
</head>
</html>
围栏代码块
Markdown基本语法允许您通过将行缩进四个空格或一个制表符来创建代码块。如果发现不方便,请尝试使用受保护的代码块。根据Markdown处理器或编辑器的不同,您将在代码块之前和之后的行上使用三个反引号(```)或三个波浪号(~~~)。
Markdown
``` { "firstName": "John", "lastName": "Smith", "age": 25 } ```
预期效果
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
代码高亮
许多Markdown处理器都支持受围栏代码块的语法突出显示。使用此功能,您可以为编写代码的任何语言添加颜色突出显示。要添加语法突出显示,请在受防护的代码块之前的反引号旁边指定一种语言。
Markdown
```json
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
```
预期效果
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
Markdown 链接语法
链接文本放在中括号内,链接地址放在后面的括号中,链接title可选。
超链接Markdown语法代码:[超链接显示名](超链接地址 "超链接title")
对应的HTML代码:<a href="超链接地址" title="超链接title">超链接显示名</a>
这是一个链接 [Markdown语法](https://markdown.com.cn)。
渲染效果如下:
这是一个链接 Markdown语法 (opens new window)。
给链接增加 Title
链接title是当鼠标悬停在链接上时会出现的文字,这个title是可选的,它放在圆括号中链接地址后面,跟链接地址之间以空格分隔。
这是一个链接 [Markdown语法](https://markdown.com.cn "最好的markdown教程")。
渲染效果如下:
这是一个链接 Markdown语法 (opens new window)。
网址和Email地址
使用尖括号可以很方便地把URL或者email地址变成可点击的链接。
<https://markdown.com.cn>
<fake@example.com>
渲染效果如下:
https://markdown.com.cn(opens new window) fake@example.com
带格式化的链接
强调 链接, 在链接语法前后增加星号。 要将链接表示为代码,请在方括号中添加反引号。
I love supporting the **[EFF](https://eff.org)**.
This is the *[Markdown Guide](https://www.markdownguide.org)*.
See the section on [`code`](#code).
渲染效果如下:
I love supporting the EFF (opens new window).
This is the Markdown Guide (opens new window).
See the section on code
.
引用类型链接
引用样式链接是一种特殊的链接,它使URL在Markdown中更易于显示和阅读。参考样式链接分为两部分:与文本保持内联的部分以及存储在文件中其他位置的部分,以使文本易于阅读。
链接的第一部分格式
引用类型的链接的第一部分使用两组括号进行格式设置。第一组方括号包围应显示为链接的文本。第二组括号显示了一个标签,该标签用于指向您存储在文档其他位置的链接。
尽管不是必需的,可以在第一组和第二组括号之间包含一个空格。第二组括号中的标签不区分大小写,可以包含字母,数字,空格或标点符号。
以下示例格式对于链接的第一部分效果相同:
[hobbit-hole][1]
[hobbit-hole] [1]
链接的第二部分格式
引用类型链接的第二部分使用以下属性设置格式:
- 放在括号中的标签,其后紧跟一个冒号和至少一个空格(例如
[label]:
)。 - 链接的URL,可以选择将其括在尖括号中。
- 链接的可选标题,可以将其括在双引号,单引号或括号中。
以下示例格式对于链接的第二部分效果相同:
[1]: https://en.wikipedia.org/wiki/Hobbit#Lifestyle
[1]: https://en.wikipedia.org/wiki/Hobbit#Lifestyle "Hobbit lifestyles"
[1]: https://en.wikipedia.org/wiki/Hobbit#Lifestyle 'Hobbit lifestyles'
[1]: https://en.wikipedia.org/wiki/Hobbit#Lifestyle (Hobbit lifestyles)
[1]: <https://en.wikipedia.org/wiki/Hobbit#Lifestyle> "Hobbit lifestyles"
[1]: <https://en.wikipedia.org/wiki/Hobbit#Lifestyle> 'Hobbit lifestyles'
[1]: <https://en.wikipedia.org/wiki/Hobbit#Lifestyle> (Hobbit lifestyles)
可以将链接的第二部分放在Markdown文档中的任何位置。有些人将它们放在出现的段落之后,有些人则将它们放在文档的末尾(例如尾注或脚注)。
Markdown 图片语法
要添加图像,请使用感叹号 (!
), 然后在方括号增加替代文本,图片链接放在圆括号里,括号里的链接后可以增加一个可选的图片标题文本。
插入图片Markdown语法代码:
。
对应的HTML代码:<img src="图片链接" alt="图片alt" title="图片title">

渲染效果如下:
链接图片
给图片增加链接,请将图像的Markdown 括在方括号中,然后将链接添加在圆括号中。
[](https://markdown.com.cn)
渲染效果如下:
Markdown 转义字符语法
要显示原本用于格式化 Markdown 文档的字符,请在字符前面添加反斜杠字符 \ 。
\* Without the backslash, this would be a bullet in an unordered list.
渲染效果如下:
* Without the backslash, this would be a bullet in an unordered list.
可做转义的字符
以下列出的字符都可以通过使用反斜杠字符从而达到转义目的。
Character | Name |
---|---|
\ | backslash |
` | backtick (see also escaping backticks in code) |
* | asterisk |
_ | underscore |
{ } | curly braces |
[ ] | brackets |
( ) | parentheses |
# | pound sign |
+ | plus sign |
- | minus sign (hyphen) |
. | dot |
! | exclamation mark |
| | pipe (see also escaping pipe in tables) |
1 comments
-
李一飞 LV 6 MOD @ 2024-11-1 15:31:30
- 1