Markdown 官方教程

Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,Markdown文件的后缀名便是“.md”。

Markdown 标题语法

要创建标题,请在单词或短语前面添加井号 (#) 。# 的数量代表了标题的级别。例如,添加三个 # 表示创建一个三级标题 (<h3>) (例如:### My Header)。

Markdown语法 HTML 预览效果
# Heading level 1 <h1>Heading level 1</h1>

Heading level 1

## Heading level 2 <h2>Heading level 2</h2>

Heading level 2

### Heading level 3 <h3>Heading level 3</h3>

Heading level 3

#### Heading level 4 <h4>Heading level 4</h4>

Heading level 4

##### Heading level 5 <h5>Heading level 5</h5>

Heading level 5

###### Heading level 6 <h6>Heading level 6</h6>

Heading level 6

最佳实践

不同的 Markdown 应用程序处理 # 和标题之间的空格方式并不一致。为了兼容考虑,请用一个空格在 # 和标题之间进行分隔。

✅  Do this ❌  Don't do this
# Here's a Heading #Here's a Heading

Markdown 段落

要创建段落,请使用空白行将一行或多行文本进行分隔。

Markdown语法 HTML 预览效果
I really like using Markdown.

I think I'll use it to format all of my documents from now on.

<p>I really like using Markdown.</p>

<p>I think I'll use it to format all of my documents from now on.</p>

I really like using Markdown.

I think I'll use it to format all of my documents from now on.

段落(Paragraph)用法的最佳实

不要用空格(spaces)或制表符( tabs)缩进段落。

✅  Do this ❌  Don't do this
Don't put tabs or spaces in front of your paragraphs.

Keep lines left-aligned like this.

    This can result in unexpected formatting problems.

Don't add tabs or spaces in front of paragraphs.

Markdown 换行语法

在一行的末尾添加两个或多个空格,然后按回车键,即可创建一个换行(<br>)。

Markdown语法 HTML 预览效果
This is the first line.  
And this is the second line.
<p>This is the first line.<br>
And this is the second line.</p>

This is the first line.
And this is the second line.

换行(Line Break)用法的最佳实践

几乎每个 Markdown 应用程序都支持两个或多个空格进行换行,称为 结尾空格(trailing whitespace) 的方式,但这是有争议的,因为很难在编辑器中直接看到空格,并且很多人在每个句子后面都会有意或无意地添加两个空格。由于这个原因,你可能要使用除结尾空格以外的其它方式来换行。幸运的是,几乎每个 Markdown 应用程序都支持另一种换行方式:HTML 的 <br> 标签。

为了兼容性,请在行尾添加“结尾空格”或 HTML 的 <br> 标签来实现换行。

还有两种其他方式我并不推荐使用。CommonMark 和其它几种轻量级标记语言支持在行尾添加反斜杠 (\) 的方式实现换行,但是并非所有 Markdown 应用程序都支持此种方式,因此从兼容性的角度来看,不推荐使用。并且至少有两种轻量级标记语言支持无须在行尾添加任何内容,只须键入回车键(return)即可实现换行。

✅  Do this ❌  Don't do this
First line with two spaces after.  
And the next line.

First line with the HTML tag after.<br>
And the next line.

First line with a backslash after.\
And the next line.

First line with nothing after.
And the next line.

Markdown 强调语法

通过将文本设置为粗体或斜体来强调其重要性。

粗体(Bold)

要加粗文本,请在单词或短语的前后各添加两个星号(asterisks)或下划线(underscores)。如需加粗一个单词或短语的中间部分用以表示强调的话,请在要加粗部分的两侧各添加两个星号(asterisks)。

Markdown语法 HTML 预览效果
I just love bold text. I just love <strong>bold text</strong>. I just love bold text.
I just love bold text. I just love <strong>bold text</strong>. I just love bold text.
Loveisbold Love<strong>is</strong>bold Loveisbold

粗体(Bold)用法最佳实践

Markdown 应用程序在如何处理单词或短语中间的下划线上并不一致。为兼容考虑,在单词或短语中间部分加粗的话,请使用星号(asterisks)。

✅  Do this ❌  Don't do this
Love**is**bold Love__is__bold

斜体(Italic)

要用斜体显示文本,请在单词或短语前后添加一个星号(asterisk)或下划线(underscore)。要斜体突出单词的中间部分,请在字母前后各添加一个星号,中间不要带空格。

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 _cat's meow_. Italicized text is the <em>cat's meow</em>. Italicized text is the cat’s meow.
A*cat*meow A<em>cat</em>meow Acatmeow

斜体(Italic)用法的最佳实践

要同时用粗体和斜体突出显示文本,请在单词或短语的前后各添加三个星号或下划线。要加粗并用斜体显示单词或短语的中间部分,请在要突出显示的部分前后各添加三个星号,中间不要带空格。

✅  Do this ❌  Don't do this
A*cat*meow A_cat_meow

粗体(Bold)和斜体(Italic)

要同时用粗体和斜体突出显示文本,请在单词或短语的前后各添加三个星号或下划线。要加粗并用斜体显示单词或短语的中间部分,请在要突出显示的部分前后各添加三个星号,中间不要带空格。

Markdown语法 HTML 预览效果
This text is ***really important***. This text is <strong><em>really important</em></strong>. This text is really important.
This text is ___really important___. This text is <strong><em>really important</em></strong>. This text is really important.
This text is __*really important*__. This text is <strong><em>really important</em></strong>. This text is really important.
This text is **_really important_**. This text is <strong><em>really important</em></strong>. This text is really important.
This is really***very***important text. This is really<strong><em>very</em></strong>important text. This is reallyveryimportant text.

粗体(Bold)和斜体(Italic)用法的最佳实践

Markdown 应用程序在处理单词或短语中间添加的下划线上并不一致。为了实现兼容性,请使用星号将单词或短语的中间部分加粗并以斜体显示,以示重要。

✅  Do this ❌  Don't do this
This is really***very***important text. This is really___very___important text.

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.

多个段落的块引用

块引用可以包含多个段落。为段落之间的空白行添加一个 > 符号。

> 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.

嵌套块引用

块引用可以嵌套。在要嵌套的段落前添加一个 >> 符号。

> 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 格式的元素。并非所有元素都可以使用,你需要进行实验以查看哪些元素有效。

> #### The quarterly results look great!
>
> - Revenue was off the chart.
> - Profits were higher than ever.
>
>  *Everything* is going according to **plan**.

渲染效果如下:

The quarterly results look great!

  • Revenue was off the chart.
  • Profits were higher than ever.

Everything is going according to plan.

Markdown 列表语法

可以将多个条目组织成有序或无序列表。

有序列表

要创建有序列表,请在每个列表项前添加数字并紧跟一个英文句点。数字不必按数学顺序排列,但是列表应当以数字 1 起始。

Markdown语法 HTML 预览效果
1. First item
2. Second item
3. Third item
4. Fourth item
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>
  1. First item
  2. Second item
  3. Third item
  4. Fourth item
1. First item
1. Second item
1. Third item
1. Fourth item
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>
  1. First item
  2. Second item
  3. Third item
  4. Fourth item
1. First item
8. Second item
3. Third item
5. Fourth item
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>
  1. First item
  2. Second item
  3. Third item
  4. Fourth item
1. First item
2. Second item
3. Third item
    1. Indented item
    2. Indented item
4. Fourth item
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item
<ol>
<li>Indented item</li>
<li>Indented item</li>
</ol>
</li>
<li>Fourth item</li>
</ol>
  1. First item
  2. Second item
  3. Third item
    1. Indented item
    2. Indented item
  4. Fourth item

有序列表最佳实践

CommonMark and a few other lightweight markup languages let you use a parenthesis ()) as a delimiter (e.g., 1) First item), but not all Markdown applications support this, so it isn’t a great option from a compatibility perspective. For compatibility, use periods only.

✅  Do this ❌  Don't do this
1. First item
2. Second item
1) First item
2) Second item

无序列表

要创建无序列表,请在每个列表项前面添加破折号 (-)、星号 (*) 或加号 (+) 。缩进一个或多个列表项可创建嵌套列表。

Markdown语法 HTML 预览效果
- First item
- Second item
- Third item
- Fourth item
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>
  • First item
  • Second item
  • Third item
  • Fourth item
* First item
* Second item
* Third item
* Fourth item
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>
  • First item
  • Second item
  • Third item
  • Fourth item
+ First item
+ Second item
+ Third item
+ Fourth item
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>
  • First item
  • Second item
  • Third item
  • Fourth item
- First item
- Second item
- Third item
    - Indented item
    - Indented item
- Fourth item
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item
<ul>
<li>Indented item</li>
<li>Indented item</li>
</ul>
</li>
<li>Fourth item</li>
</ul>
  • First item
  • Second item
  • Third item
    • Indented item
    • Indented item
  • Fourth item

无序列表最佳实践

Markdown applications don’t agree on how to handle different delimiters in the same list. For compatibility, don't mix and match delimiters in the same list — pick one and stick with it.

✅  Do this ❌  Don't do this
- First item
- Second item
- Third item
- Fourth item
+ First item
* Second item
- Third item
+ Fourth 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.

渲染效果如下:

  • 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.> 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.

代码块

代码块通常采用四个空格或一个制表符缩进。当它们被放在列表中时,请将它们缩进八个空格或两个制表符。

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.

渲染效果如下:

  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.

图片

1.  Open the file containing the Linux mascot.
2.  Marvel at its beauty.![Tux, the Linux mascot](/assets/images/tux.png)3.  Close the file.

渲染效果如下:

  1. Open the file containing the Linux mascot.

  2. Marvel at its beauty.

  3. Close the file.

列表

You can nest an unordered list in an ordered list, or vice versa.

1. First item
2. Second item
3. Third item- Indented item- Indented item
4. Fourth item

渲染效果如下:

  1. First item
  2. Second item
  3. Third item
    • Indented item
    • Indented item
  4. Fourth item

Markdown 分隔线语法

要创建分隔线,请在单独一行上使用三个或多个星号 (***)、破折号 (---) 或下划线 (___) ,并且不能包含其他内容。

***---_________________

以上三个分隔线的渲染效果看起来都一样:


分隔线(Horizontal Rule)用法最佳实践

为了兼容性,请在分隔线的前后均添加空白行。

✅  Do this ❌  Don't do this
Try to put a blank line before...

---

...and after a horizontal rule.

Without blank lines, this would be a heading.
---
Don't do this!

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)

特殊字符自动转义

在 HTML 文件中,有两个字符需要特殊处理: < 和 & 。 < 符号用于起始标签,& 符号则用于标记 HTML 实体,如果你只是想要使用这些符号,你必须要使用实体的形式,像是 &lt; 和 &amp;

& 符号其实很容易让写作网页文件的人感到困扰,如果你要打「AT&T」 ,你必须要写成「AT&amp;T」 ,还得转换网址内的 & 符号,如果你要链接到:

http://images.google.com/images?num=30&q=larry+bird

你必须要把网址转成:

http://images.google.com/images?num=30&amp;q=larry+bird

才能放到链接标签的 href 属性里。不用说也知道这很容易忘记,这也可能是 HTML 标准检查所检查到的错误中,数量最多的。

Markdown 允许你直接使用这些符号,它帮你自动转义字符。如果你使用 & 符号的作为 HTML 实体的一部分,那么它不会被转换,而在其它情况下,它则会被转换成 &amp;。所以你如果要在文件中插入一个著作权的符号,你可以这样写:

&copy;

Markdown 将不会对这段文字做修改,但是如果你这样写:

AT&T

Markdown 就会将它转为:

AT&amp;T

类似的状况也会发生在 < 符号上,因为 Markdown 支持 行内 HTML ,如果你使用 < 符号作为 HTML 标签的分隔符,那 Markdown 也不会对它做任何转换,但是如果你是写:

4 < 5

Markdown 将会把它转换为:

4 &lt; 5

需要特别注意的是,在 Markdown 的块级元素和内联元素中, < 和 & 两个符号都会被自动转换成 HTML 实体,这项特性让你可以很容易地用 Markdown 写 HTML。(在 HTML 语法中,你要手动把所有的 < 和 & 都转换为 HTML 实体。)

Markdown 官方教程相关推荐

  1. MarkDown官方教程

    这里写自定义目录标题 欢迎使用Markdown编辑器 新的改变 功能快捷键 合理的创建标题,有助于目录的生成 如何改变文本的样式 插入链接与图片 如何插入一段漂亮的代码片 生成一个适合你的列表 创建一 ...

  2. 【Markdown基础教程】Markdown介绍

    本文主要讲解关于Markdown的概念 1.Markdown是什么? Markdown是什么?有什么特点?,这就是我最开始看到这个单词的想法. 于是,总结出来这几条 1.Markdown是一种轻量级标 ...

  3. Markdown 简明教程

    Markdown 简明教程 1. 标题 为了获得上面的 "1. 标题", 在 Markdown 编辑器里输入: # 1. 标题 "#" 后最好加个空格.除此之外 ...

  4. CSDN Markdown简明教程3-表格和公式

    0. 目录 目录 前言 表格 1 表格 2 表格对齐方式 公式 1 行内公式 2 陈列公式displayed formulas 3 MathJax语法 深入 声明 1. 前言 Markdown是一种轻 ...

  5. 【Flask】官方教程(Tutorial)-part4(完结)测试覆盖度、部署到生产、持续开发

    前序文章: 官方教程(Tutorial)-part1:项目布局.应用程序设置.定义和访问数据库 官方教程(Tutorial)-part2:蓝图-视图.模板.静态文件 官方教程(Tutorial)-pa ...

  6. OkHttp官方教程解析-彻底入门OkHttp使用

    最近半年来身边开发的朋友越来越多的提到OkHttp,上谷歌百度一下,确实OkHttp成了时下最火的HTTP框架,于是我也开始放下Volley,转而关注OkHttp,五一期间仔细看了官方WiKi介绍(我 ...

  7. opencv python下载_[福利] OpenCV4 Python 最新中文版官方教程来了(附下载)

    教程简介 OpenCV 是计算机视觉中经典的专用库,然而其中文版官方教程久久不来.近日,一款最新 OpenCV4.1 版本的完整中文版官方教程出炉,读者朋友可以更好的学习了解 OpenCV 相关细节. ...

  8. basler相机参数简要中文说明_附下载| OpenCV最新中文版官方教程

    OpenCV是计算机视觉中经典的专用库,然而其中文版官方教程久久不来.近日,一款最新OpenCV4.1 版本的完整中文版官方教程出炉,读者朋友可以更好的学习了解OpenCV相关细节.教程根据官方提供的 ...

  9. 福利,PyTorch中文版官方教程来啦(附下载)

    PyTorch 中文版官方教程来了. PyTorch 是近期最为火爆的深度学习框架之一,然而其中文版官方教程久久不来.近日,一款完整的 PyTorch 中文版官方教程出炉,读者朋友从中可以更好的学习了 ...

最新文章

  1. sdk没有登录什么意思_不需要接入SDK的第三方登录及分享
  2. Express4.x API (四):Router (译)
  3. 百行代码打造一个DI容器(支持瞬时生命周期、单利生命周期、构造函数自动注入、属性自动注入、字段自动注入)...
  4. 【MySQL】MySQL的group_concat使用例子
  5. Hibernate 缓存
  6. 【flink】Flink 1.12.2 源码浅析 :Task数据输出
  7. css3 中心点,用css3实现打点效果实例讲解
  8. 漫画:如何优化 “字符串匹配算法”?
  9. 从10秒到2秒!ElasticSearch性能调优实践
  10. 【技术贴】解决开机本地连接出来慢,本地连接开机后出来时间慢
  11. JavaWbe中文乱码解决方案
  12. python随机森林回归数据实战
  13. 简单一招就能进行不同平台的推文转移,复制粘贴。
  14. adb 查看浏览器内核版本
  15. yolov5深度剖析+源码debug级讲解系列(二)backbone构建
  16. 中文分词 正向最大匹配法 逆向最大匹配法 双向最大匹配法
  17. Ubuntu 使用命令向QQ邮箱发送邮件
  18. python开发基础之数据类型、字符编码、文件操作
  19. Java中的多线程安全问题
  20. 敏捷计划:是一个多层次的计划洋葱

热门文章

  1. ISCW实验8:配置Cisco与Windows进行IPSec通信
  2. Golang 环境变量须知
  3. Linux 命令(115)—— rev 命令
  4. OO第一单元总结——多项式求导
  5. “Hello, my first blog”------第一篇博客的仪式感
  6. Java集合框架使用总结
  7. windows Server 2008各版本区别详解
  8. eclipse3.2 汉化 汉化包下载
  9. (纯代码)图片移动放大缩小:
  10. SDK里报错[NSConcreteMutableData wbsdk_base64EncodedString]