Markdown是一種輕量級的標記語言,可用于將格式設置元素添加到純文本文檔中。Markdown 由 John Gruber 于2004年創(chuàng)建,如今已成為世界上最受歡迎的標記語言之一。
Markdown基本語法
標題
要創(chuàng)建標題,在單詞或短語前面加數(shù)字符號 #,數(shù)字符號的數(shù)量和標題級別對應
(# Heading level 1) 對應 (<h1>Heading level 1</h1>)
(## Heading level 2) 對應 (<h2>Heading level 2</h2>)
(### Heading level 3) 對應 (<h3>Heading level 3</h3>)
(#### Heading level 4) 對應 (<h4>Heading level 4</h4>)
(##### Heading level 5) 對應 (<h5>Heading level 5</h5>)
(###### Heading level 6) 對應 (<h5>Heading level 6</h6>)
段落
要創(chuàng)建段落,請使用空白行分隔一行或多行文本。您不應縮進帶有空格或制表符的段落。
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>
換行
要創(chuàng)建換行符(<br>),請以兩個或多個空格結束一行,然后鍵入return。
| Markdown | HTML | 渲染輸出 |
|---|---|---|
| This is the first line. And this is the second line. |
<p>his is the first line.< br >And this is the second line</p> | 這是第一行。 這是第二行。 |
著重
可以過使文本變?yōu)榇煮w或斜體來增加著重。
粗體
要加粗文本,請在單詞或短語的前后添加兩個星號或下劃線。要加粗一個單詞的中部以強調(diào),請在字母周圍添加兩個星號,且各空格之間不加空格。
| 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>. |
這段文字真的很重要。 |
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>. |
這段文字真的很重要。 |
塊引用
要創(chuàng)建blockquote,請>在段落前面添加一個。
> Dorothy followed her through many of the beautiful rooms in her castle.
呈現(xiàn)的輸出如下所示:
桃樂絲(Dorothy)跟著她走過了她城堡中許多美麗的房間。
具有多個段落的塊引用塊引用可以包含多個段落。>在段落之間的空白行上添加一個。
> 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.
呈現(xiàn)的輸出如下所示:
桃樂絲(Dorothy)跟著她走過了她城堡中許多美麗的房間。
女巫請她清洗鍋碗瓢盆,掃地,并用木柴取火。
嵌套塊引用塊引用可以嵌套。>>在要嵌套的段落前面添加一個。
> 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.
呈現(xiàn)的輸出如下所示:
桃樂絲(Dorothy)跟著她走過了她城堡中許多美麗的房間。
女巫請她清洗鍋碗瓢盆,掃地,并用木柴取火。
具有其他元素的塊引用
塊引用可以包含其他Markdown格式的元素。并非所有元素都可以使用-您需要進行實驗以查看哪些元素有效。
> #### The quarterly results look great!
>
> - Revenue was off the chart.
> - Profits were higher than ever.
>
> *Everything* is going according to **plan**.
呈現(xiàn)的輸出如下所示:
季度業(yè)績看起來不錯!
- 收入超出了預期。
- 利潤比以往任何時候都高。
一切都按計劃進行。
清單
您可以將項目組織成有序和無序列表。
有序列表
要創(chuàng)建有序列表,請在訂單項中添加數(shù)字和句點。數(shù)字不必按數(shù)字順序排列,但列表應以數(shù)字開頭。
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>
- 第一項
- 第二項
- 第三項
- 第四項
無序列表
要創(chuàng)建無序列表,請在訂單項前添加破折號(-),星號(*)或加號(+)??s進一個或多個項目以創(chuàng)建嵌套列表。
- 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
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>
在列表中添加元素
要在保留列表連續(xù)性的同時在列表中添加另一個元素,請將該元素縮進四個空格或一個制表符,如以下示例所示。
段落
* 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.
呈現(xiàn)的輸出如下所示:
這是第一個列表項。
-
這是第二個列表項。
我需要在第二個列表項下面添加另一段。
這是第三個列表項。
塊引用
* 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.
呈現(xiàn)的輸出如下所示:
這是第一個列表項。
-
這是第二個列表項。
在第二個列表項的下方,blockquote看起來不錯。
這是第三個列表項。
代碼塊
[代碼塊](??s進四個空格或一個制表符。當它們在列表中時,將它們縮進八個空格或兩個選項卡。
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.
呈現(xiàn)的輸出如下所示:
打開文件。
-
在第21行找到以下代碼塊:
<html> <head> <title>Test</title> </head> 更新標題以匹配您的網(wǎng)站名稱。
圖片
1\. Open the file containing the Linux mascot.
2\. Marvel at its beauty.

3\. Close the file.
呈現(xiàn)的輸出如下所示:
打開包含Linux吉祥物的文件。
-
驚嘆于它的美麗。
Tux,Linux吉祥物 關閉文件。
代碼
將單詞或短語表示為代碼,請將其括在勾號(```)中。
| Markdown | HTML | 渲染輸出 |
|---|---|---|
At the command prompt, typenano.
|
At the command prompt, type <code>nano</code>. |
在命令提示符下,鍵入nano。 |
轉義刻度線
如果要表示為代碼的單詞或短語包含一個或多個刻度線,可以通過將單詞或短語括在雙刻度線(````)中來對其進行轉義。
| Markdown | HTML | 渲染輸出 |
|---|---|---|
Use `code` in your Markdown file. |
<code>Usecodein your Markdown file.</code>
|
Usecodein your Markdown file.
|
代碼塊
要創(chuàng)建代碼塊,請在代碼塊的每一行縮進至少四個空格或一個制表符。
<html>
<head>
</head>
</html>
呈現(xiàn)的輸出如下所示:
<html>
<head>
</head>
</html>
注意:要創(chuàng)建沒有縮進線的代碼塊,請使用圍柵代碼塊。
水平線
要創(chuàng)建水平線***,請單獨在一行上使用三個或更多的星號(),破折號(---)或下劃線(___)。
***
---
_________________
所有這三個的渲染輸出看起來都相同:
鏈接
要創(chuàng)建鏈接,請將鏈接文本括在方括號(例如[Duck Duck Go])中,然后立即在URL后面加上括號(例如(https://duckduckgo.com))中的URL 。
My favorite search engine is [Duck Duck Go](https://duckduckgo.com).
呈現(xiàn)的輸出如下所示:
我最喜歡的搜索引擎是Duck Duck Go。
添加標題
您可以選擇為鏈接添加標題。當用戶將鼠標懸停在鏈接上時,這將顯示為工具提示。要添加標題,請將其括在URL后面的括號中。
My favorite search engine is [Duck Duck Go](https://duckduckgo.com "The best search engine for privacy").
呈現(xiàn)的輸出如下所示:
我最喜歡的搜索引擎是Duck Duck Go。
網(wǎng)址和電子郵件地址
要將URL或電子郵件地址快速轉換為鏈接,請將其括在尖括號中。
<https://markdown.p2hp.com>
<fake@example.com>
呈現(xiàn)的輸出如下所示:
https://markdown.p2hp.com
fake@example.com
格式化鏈接
為了強調(diào)接,請在方括號和括號之前和之后添加星號。
I love supporting the **[EFF](https://eff.org)**.
This is the *[Markdown Guide](https://markdown.p2hp.com)*.
呈現(xiàn)的輸出如下所示:
我喜歡支持EFF。
這是《Markdown指南》。
參考樣式鏈接
引用樣式鏈接是一種特殊的鏈接,它使URL在Markdown中更易于顯示和閱讀。引用樣式的鏈接分為兩部分:與文本保持內(nèi)聯(lián)的部分以及在文件中其他位置存儲的部分,以使文本易于閱讀。
格式化鏈接的第一部分
參考樣式鏈接的第一部分使用兩組括號進行格式化。第一組方括號包圍應顯示為鏈接的文本。第二組括號顯示了一個標簽,該標簽用于指向您存儲在文檔其他位置的鏈接。
盡管不是必需的,但您可以在第一組和第二組支架之間包含一個空格。第二組括號中的標簽不區(qū)分大小寫,可以包含字母,數(shù)字,空格或標點符號。
這意味著以下示例格式對于鏈接的第一部分大致相同:
[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文檔中的任何位置。有些人將它們放在出現(xiàn)的段落之后,而其他人則將它們放在文檔的末尾(例如尾注或腳注)。
將零件放在一起的示例
假設您添加一個URL作為到段落的標準URL鏈接,并且在Markdown中看起來像這樣:
In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends
of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
eat: it was a [hobbit-hole](https://en.wikipedia.org/wiki/Hobbit#Lifestyle "Hobbit lifestyles"), and that means comfort.
盡管它可能指向有趣的附加信息,但顯示的URL確實不會給現(xiàn)有的原始文本增加太多,除了使其難以閱讀之外。要解決此問題,您可以改為設置網(wǎng)址格式:
In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends
of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
eat: it was a [hobbit-hole][1], and that means comfort.
[1]: <https://en.wikipedia.org/wiki/Hobbit#Lifestyle> "Hobbit lifestyles"
在上述兩種情況下,呈現(xiàn)的輸出將相同:
在地上的一個洞里住著一個霍比特人。這不是一個骯臟,骯臟,潮濕的洞,里面充滿蠕蟲的末端和難聞的氣味,也沒有一個干燥,裸露,沙質的洞,里面沒有東西可以坐下或進食:那是一個霍比特洞,意味著舒適。
鏈接HTML為:
<a title="Hobbit lifestyles">hobbit-hole</a>
圖片
要添加圖像,請?zhí)砑痈袊@號(!),然后在括號中添加替代文本,并在括號中添加圖像資源的路徑或URL。您可以選擇在括號中的URL之后添加標題。

呈現(xiàn)的輸出如下所示:

鏈接圖像
要向圖像添加鏈接,請將圖像的Markdown括在方括號中,然后在括號中添加鏈接。
[](https://www.flickr.com/photos/beaurogers/31833779864/in/photolist-Qv3rFw-34mt9F-a9Cmfy-5Ha3Zi-9msKdv-o3hgjr-hWpUte-4WMsJ1-KUQ8N-deshUb-vssBD-6CQci6-8AFCiD-zsJWT-nNfsgB-dPDwZJ-bn9JGn-5HtSXY-6CUhAL-a4UTXB-ugPum-KUPSo-fBLNm-6CUmpy-4WMsc9-8a7D3T-83KJev-6CQ2bK-nNusHJ-a78rQH-nw3NvT-7aq2qf-8wwBso-3nNceh-ugSKP-4mh4kh-bbeeqH-a7biME-q3PtTf-brFpgb-cg38zw-bXMZc-nJPELD-f58Lmo-bXMYG-bz8AAi-bxNtNT-bXMYi-bXMY6-bXMYv)
呈現(xiàn)的輸出如下所示:
轉義字符
要顯示原義字符,否則將用于設置Markdown文檔中的文本格式\,請在字符前面添加反斜杠()。
\* Without the backslash, this would be a bullet in an unordered list.
呈現(xiàn)的輸出如下所示:
*如果沒有反斜杠,這將是無序列表中的項目符號。
你可以轉義的字符
您可以使用反斜杠轉義以下字符。
| 字符 | 名稱 | |
|---|---|---|
| \ | 反斜杠 | |
| ` | 刻度線(另請參見[轉義刻度線中的代碼]) | |
| * | 星號 | |
| _ | 下劃線 | |
| {} | 大括號 | |
| [] | 中括號 | |
| () | 括號 | |
| # | 井號 | |
| + | 加號 | |
| - | 減號(連字符) | |
| . | 點 | |
| ! | 感嘆號 |
轉自 markdown中文網(wǎng)

