markdown书写备忘录
总览
几乎所有Markdown应用程序都支持John Gruber原始设计文档中概述的基本语法。Markdown处理器之间存在细微的差异和差异-尽可能在线内注明。
注意:使用Markdown并不意味着您也不能使用HTML。您可以将HTML标签添加到任何Markdown文件中。如果您更喜欢某些HTML标记而不是Markdown语法,这将很有帮助。例如,有些人发现将HTML标签用于图像更容易。
标题
要创建标题,请#
在单词或短语的前面添加数字符号()。您使用的数字符号的数量应与标题级别相对应。例如,要创建标题级别三(<h3>
),请使用三个数字符号(例如### My Header
)。
Markdown | HTML | 渲染输出 |
---|---|---|
# Heading level 1 | <h1>Heading level 1</h1> | 标题等级1 |
## Heading level 2 | <h2>Heading level 2</h2> | 标题等级2 |
### Heading level 3 | <h3>Heading level 3</h3> | 标题级别3 |
#### Heading level 4 | <h4>Heading level 4</h4> | 标题级别4 |
##### Heading level 5 | <h5>Heading level 5</h5> | 标题级别5 |
###### Heading level 6 | <h6>Heading level 6</h6> | 标题等级6 |
替代语法
或者,在文本下方的行上,添加任意数量的==
标题级别1的--
字符或标题级别2的字符。
Markdown | HTML | 渲染输出 |
---|---|---|
Heading level 1 =============== |
<h1>Heading level 1</h1> | 标题等级1 |
Heading level 2 ————— |
<h2>Heading level 2</h2> | 标题等级2 |
段落
要创建段落,请使用空白行分隔一行或多行文本。您不应缩进带有空格或制表符的段落。
Markdown | HTML | 渲染输出 |
---|---|---|
I really like using Markdown. | <p>I really like using Markdown.</p> | 我真的很喜欢使用Markdown。 |
I think I’ll use it to format all of my documents from now on. | <p>I think I’ll use it to format all of my documents from now on.</p> | 我想从现在开始,我将使用它来格式化所有文档。 |
换行
要创建换行符(<br>
),请以两个或多个空格结束一行,然后键入return。
Markdown | HTML | 渲染输出 |
---|---|---|
This is the first line. And this is the second line. |
<p>This is the first line. And this is the second line.</p> |
这是第一行。 这是第二行。 |
着重
您可以通过使文本变为粗体或斜体来增加着重。
粗体
要加粗文本,请在单词或短语的前后添加两个星号或下划线。要加粗一个单词的中部以强调,请在字母周围添加两个星号,且各空格之间不加空格。
Markdown | HTML | 渲染输出 |
---|---|---|
I just love **bold text**. |
I just love <strong>bold text</strong>. |
我只喜欢粗体字。 |
I just love __bold text__. |
I just love <strong>bold text</strong>. |
我只喜欢粗体字。 |
Love**is**bold |
Love<strong>is</strong>bold |
爱是大胆的 |
斜体
要斜体显示文本,请在单词或短语的前后添加一个星号或下划线。要斜体突出单词的中间部分,请在字母周围添加一个星号,中间不要带空格。
Markdown | HTML | 渲染输出 |
---|---|---|
Italicized text is the *cat's meow*. |
Italicized text is the <em>cat's meow</em>. |
斜体文字是猫的叫声。 |
Italicized text is the _cat's meow_. |
Italicized text is the <em>cat's meow</em>. |
斜体文字是猫的叫声。 |
A*cat*meow |
A<em>cat</em>meow |
一个猫喵 |
粗体和斜体
要同时突出显示带有粗体和斜体的文本,请在单词或短语的前后添加三个星号或下划线。
Markdown | HTML | 渲染输出 | |||
---|---|---|---|---|---|
This text is really important. | This text is <strong><em>really important</em></strong>. |
这段文字真的很重要。 | |||
This text is really important. | This text is <strong><em>really important</em></strong>. |
这段文字___真的很重要___。 |
块引用
要创建blockquote,请在段落前面添加一个>
。
1 | > Dorothy followed her through many of the beautiful rooms in her castle. |
呈现的输出如下所示:
桃乐丝(Dorothy)跟着她走过了她城堡中许多美丽的房间。
具有多个段落的块引用
块引用可以包含多个段落。在段落之间的空白行上添加一个>
。
1 | > Dorothy followed her through many of the beautiful rooms in her castle. |
呈现的输出如下所示:
桃乐丝(Dorothy)跟着她走过了她城堡中许多美丽的房间。
女巫请她清洗锅碗瓢盆,扫地,并用木柴取火。
嵌套块引用
块引用可以嵌套。>>
在要嵌套的段落前面添加一个。
1 | > Dorothy followed her through many of the beautiful rooms in her castle. |
呈现的输出如下所示:
桃乐丝(Dorothy)跟着她走过了她城堡中许多美丽的房间。
女巫请她清洗锅碗瓢盆,扫地,并用木柴取火。
具有其他元素的块引用
块引用可以包含其他Markdown格式的元素。并非所有元素都可以使用-
您需要进行实验以查看哪些元素有效。
1 | > The quarterly results look great! |
呈现的输出如下所示:
季度业绩看起来不错!
- 收入超出了预期。
- 利润比以往任何时候都高。
一切都按计划进行。
清单
您可以将项目组织成有序和无序列表。
有序列表
要创建有序列表,请在订单项中添加数字和句点。数字不必按数字顺序排列,但列表应以数字开头。
Markdown | 渲染输出 | |||
---|---|---|---|---|
1. First item 2. Second item 3. Third item 4. Fourth item |
1. 第一项 2. 第二项 3. 第三项 4. 第四项 |
|||
1. First item 1. Second item 1. Third item 1. Fourth item |
1. 第一项 2. 第二项 3. 第三项 4. 第四项 |
|||
1. First item 8. Second item 3. Third item 5. Fourth item |
1. 第一项 2. 第二项 3. 第三项 4. 第四项 |
无序列表
要创建无序列表,请在订单项前添加破折号(-
),星号(*
)或加号(+
)。缩进一个或多个项目以创建嵌套列表。
1 | - First item |
显示为:
- First item
- Second item
- Third item
- Fourth item
在列表中添加元素
要在保留列表连续性的同时在列表中添加另一个元素,请将该元素缩进四个空格或一个制表符,如以下示例所示。
段落
1 | * This is the first list item. |
呈现的输出如下所示:
这是第一个列表项。
这是第二个列表项。
我需要在第二个列表项下面添加另一段。
这是第三个列表项。
块引用
1 | * This is the first list item. |
呈现的输出如下所示:
- 这是第一个列表项。
- 这是第二个列表项。
在第二个列表项的下方,blockquote看起来不错。
- 这是第三个列表项。
代码块
代码块通常缩进四个空格或一个制表符。当它们在列表中时,将它们缩进八个空格或两个选项卡。
1 | 1. Open the file. |
呈现的输出如下所示:
打开文件。
在第21行找到以下代码块:
1
2
3
4<html>
<head>
<title>Test</title>
</head>更新标题以匹配您的网站名称。
图片
1 | 1. Open the file containing the Linux mascot. |
呈现的输出如下所示:
打开包含Linux吉祥物的文件。
惊叹于它的美丽。
关闭文件。
代码
要将单词或短语表示为代码,请将其括在勾号(``)中。
Markdown | HTML | 渲染输出 |
---|---|---|
At the command prompt, type nano . |
At the command prompt, type <code>nano</code>. | 在命令提示符下,键入nano 。 |
代码块
要创建代码块,请在代码块的每一行缩进至少四个空格或一个制表符。
1 | <html> |
呈现的输出如下所示:
1 | <html> |
水平线
要创建水平线***,请单独在一行上使用三个或更多的星号(),破折号(-–)或下划线(___)。
1 | *** |
所有这三个的渲染输出看起来都相同:
链接
要创建链接,请将链接文本括在方括号(例如[Duck Duck Go])中,然后立即在URL后面加上括号(例如(https://duckduckgo.com))中的URL 。
1 | My favorite search engine is [Duck Duck Go](https://duckduckgo.com). |
呈现的输出如下所示:
我最喜欢的搜索引擎是Duck Duck Go。
添加标题
您可以选择为链接添加标题。当用户将鼠标悬停在链接上时,这将显示为工具提示。要添加标题,请将其括在URL后面的括号中。
1 | My favorite search engine is [Duck Duck Go](https://duckduckgo.com "The best search engine for privacy"). |
呈现的输出如下所示:
我最喜欢的搜索引擎是Duck Duck Go。
图片
要添加图像,请添加感叹号(!),然后在括号中添加替代文本,并在括号中添加图像资源的路径或URL。您可以选择在括号中的URL之后添加标题。
1 | ![Philadelphia's Magic Gardens. This place was so cool!](/assets/images/philly-magic-gardens.jpg "Philadelphia's Magic Gardens") |
呈现的输出如下所示:
表格
要添加表,请使用三个或多个连字符(---
)创建每列的标题,并使用管道(|
)分隔每列。您可以选择在表的任一端添加管道。
1 | | Syntax | Description | |
呈现的输出如下所示:
句法 | 描述 |
---|---|
标头 | 标题 |
段 | 文本 |
像元宽度可以变化,如下所示。呈现的输出将看起来相同。
1 | | Syntax | Description | |
提示:使用连字符和管道创建表可能很麻烦。为了加快这一过程,请尝试使用Markdown Tables Generator。使用图形界面构建表,然后将生成的Markdown格式的文本复制到文件中。
对齐
您可以通过:
在标题行内的连字符的左侧,右侧或两侧添加一个冒号(::
),以使列中的文本左,右或居中对齐。
1 | | Syntax | Description | Test Text | |
呈现的输出如下所示:
句法 | 描述 | 测试文字 |
---|---|---|
标头 | 标题 | 这是这个 |
段 | 文本 | 和更多 |
围栏代码块
Markdown基本语法允许您通过将行缩进四个空格或一个制表符来创建代码块。如果发现不方便,请尝试使用受保护的代码块。根据Markdown处理器或编辑器的不同,您将在代码块之前和之后的行上使用三个刻度线(```)或三个波浪号(~~~)。最好的部分?您不必缩进任何行
1 | ``` |
呈现的输出如下所示:
1 | { |
语法高亮
许多Markdown处理器都支持围栏代码块的语法突出显示。此功能使您可以为代码编写时使用的任何语言添加颜色突出显示。要添加语法突出显示,请在受防护的代码块之前的对号旁指定一种语言。
1 | ```json |
呈现的输出如下所示:
1 | { |
标题编号
许多Markdown处理器支持标题的自定义ID-一些Markdown处理器会自动添加它们。添加自定义的ID,您可以直接链接到标题,并用CSS修改。要添加自定义标题ID,请在与标题相同的行上用大括号括起该自定义ID。
1 | ### My Great Heading {#custom-id} |
HTML看起来像这样:
1 | <h3 id="custom-id">My Great Heading</h3> |
链接到标题ID
通过创建带有数字符号()和自定义标题ID 的标准链接,可以链接到文件中具有自定义ID #
的标题。
Markdown | HTML | 渲染输出 |
---|---|---|
[Heading IDs](#heading-ids) |
<a href="#heading-ids">Heading IDs</a> |
标题编号 |
通过将自定义标题ID添加到网页的完整URL(例如,[Heading IDs](http://markdown.p2hp.com/extended-syntax#heading-ids)
),其他网站可以链接到标题。
删除线
您可以通过在单词中心放置一条水平线来“删除”单词。结果看起来像这样。此功能使您可以指示某些单词是一个错误,并不表示要包含在文档中。若要删除单词,请~~
在单词前后使用两个波浪号()。
1 | ~~The world is flat.~~ We now know that the world is round. |
呈现的输出如下所示:
世界是和平的 我们现在知道世界是圆的。
任务清单
任务列表使您可以创建带有复选框的项目列表。在支持任务列表的Markdown应用程序中,复选框将显示在内容旁边。要创建任务列表,请在任务列表项之前添加破折号(-
)和方括号,并[ ]
在其前面加上一个空格()。要选择一个复选框,请x
在方括号([x]
)之间添加in 。
1 | - [x] Write the press release |
或者:
1 | <input checked disabled="" type="checkbox"> |
呈现的输出如下所示:
Write the press release
Update the website
- Write the press release
- Update the website
- Contact the media
- 感谢您的赞赏。