Markdown 語法指南

格式化您文件的必備語法

概覽

Markdown 是一種輕量標記語言,可讓您為純文字文件加入格式化元素。由 John Gruber 於 2004 年建立,Markdown 現為全球最普及的標記語言之一。

使用 Markdown 不同於使用所見即所得編輯器。在 Microsoft Word 這類程式中,您點按按鈕來格式化文字與片語,變更會立即顯示。Markdown 不是這樣。建立 Markdown 格式檔案時,您會在文字中加入 Markdown 語法,標示哪些文字與片語應以不同樣式顯示。

標題

要建立標題,在單字或片語前加上井字號 (#)。井字號數量應對應標題層級。例如要建立三級標題,使用三個井字號(如 ### 我的標題)。

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 語法
HTML 標籤
轉譯輸出
I really like using Markdown.

It lets me write easily.
<p>I really like using Markdown.</p>
<p>It lets me write easily.</p>

I really like using Markdown.

It lets me write easily.

換行

要建立換行或新行,在行末加上兩個以上空格,然後按 Enter。

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.

強調

可將文字設為粗體或斜體以加入強調。

粗體

粗體文字:在單字或片語前後各加兩個星號 (**) 或底線 (__)。

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.

斜體

斜體文字:在單字或片語前後各加一個星號 (*) 或底線 (_)。

Markdown 語法
HTML 標籤
轉譯輸出
The *cat* meows.
The <em>cat</em> meows.

The cat meows.

The _cat_ meows.
The <em>cat</em> meows.

The cat meows.

粗體與斜體

同時以粗體與斜體強調:在單字或片語前後各加三個星號 (***) 或底線 (___)。

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.

區塊引用

要建立區塊引用,在段落前加上 >。

Markdown 語法
HTML 標籤
轉譯輸出
> Dorothy followed her through many of the beautiful rooms in her castle.
<blockquote><p>Dorothy followed her through many of the beautiful rooms in her castle.</p></blockquote>

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 語法
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

無序清單

要建立無序清單,在行項目前加上破折號 (-)、星號 (*) 或加號 (+)。

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

程式碼

要將單字或片語標為程式碼,以反引號 (`) 包住。

Markdown 語法
HTML 標籤
轉譯輸出
At the command prompt, type `nano`.
At the command prompt, type <code>nano</code>.

At the command prompt, type nano.

程式碼區塊

要建立程式碼區塊,將區塊每行至少縮排四個空格或一個 Tab,或在區塊前後使用三個反引號 (```)。

Markdown 語法
轉譯輸出
```
{
  "firstName": "John",
  "lastName": "Smith",
  "age": 25
}
```
{
  "firstName": "John",
  "lastName": "Smith",
  "age": 25
}

水平線

要建立水平線,單獨一行使用三個以上星號 (***)、破折號 (---) 或底線 (___)。

Markdown 語法
HTML 標籤
轉譯輸出
***
<hr>

---
<hr>

___
<hr>

圖片

要加入圖片,先加驚嘆號 (!),接著方括號內的替代文字,以及括號內的圖片路徑或 URL。可選擇性在路徑或 URL 後以引號加入標題。

Markdown 語法
HTML
轉譯輸出
![The San Juan Mountains](https://mdg.imgix.net/assets/images/san-juan-mountains.jpg "San Juan Mountains")
<img src="https://mdg.imgix.net/assets/images/san-juan-mountains.jpg" alt="The San Juan Mountains" title="San Juan Mountains">
The San Juan Mountains

跳脫字元

要顯示在 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.

可跳脫的字元

可使用反斜線跳脫以下字元:

\backslash
`backtick
*asterisk
_underscore
{ }curly braces
[ ]brackets
( )parentheses
#pound sign
+plus sign
-minus sign (hyphen)
.dot
!exclamation mark
|pipe

表格

要加入表格,以三個以上連字號 (---) 建立每欄標題,以直線 (|) 分隔各欄。可選擇性在表格兩端加直線。

Markdown 語法
轉譯輸出
| Syntax    | Description |
| --------- | ----------- |
| Header    | Title       |
| Paragraph | Text        |
SyntaxDescription
HeaderTitle
ParagraphText

對齊

在標題列連字號左側、右側或兩側加冒號 (:) 可將欄內文字左對齊、右對齊或置中。

Markdown 語法
轉譯輸出
| Align Left | Align Center | Align Right |
| :--- | :---: | ---: |
| This | This | This |
| column | column | column |
| will | will | will |
| align | align | align |
| left | center | right |
左對齊置中右對齊
ThisThisThis
columncolumncolumn
willwillwill
alignalignalign
leftcenterright