Markdown 語法指南
格式化您文件的必備語法
概覽
Markdown 是一種輕量標記語言,可讓您為純文字文件加入格式化元素。由 John Gruber 於 2004 年建立,Markdown 現為全球最普及的標記語言之一。
使用 Markdown 不同於使用所見即所得編輯器。在 Microsoft Word 這類程式中,您點按按鈕來格式化文字與片語,變更會立即顯示。Markdown 不是這樣。建立 Markdown 格式檔案時,您會在文字中加入 Markdown 語法,標示哪些文字與片語應以不同樣式顯示。
標題
要建立標題,在單字或片語前加上井字號 (#)。井字號數量應對應標題層級。例如要建立三級標題,使用三個井字號(如 ### 我的標題)。
Heading level 1
Heading level 2
Heading level 3
Heading level 4
Heading level 5
Heading level 6
段落
要建立段落,以空行分隔一行或多行文字。
It lets me write easily.
<p>It lets me write easily.</p>
I really like using Markdown.
It lets me write easily.
換行
要建立換行或新行,在行末加上兩個以上空格,然後按 Enter。
And this is the second line.
And this is the second line.</p>
This is the first line.
And this is the second line.
強調
可將文字設為粗體或斜體以加入強調。
粗體
粗體文字:在單字或片語前後各加兩個星號 (**) 或底線 (__)。
I just love bold text.
I just love bold text.
斜體
斜體文字:在單字或片語前後各加一個星號 (*) 或底線 (_)。
The cat meows.
The cat meows.
粗體與斜體
同時以粗體與斜體強調:在單字或片語前後各加三個星號 (***) 或底線 (___)。
This text is really important.
This text is really important.
區塊引用
要建立區塊引用,在段落前加上 >。
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.
清單
可將項目整理成有序與無序清單。
有序清單
要建立有序清單,加入以數字加句點開頭的行項目。數字不必依序,但清單應從一開始。
2. Second item
3. Third item
4. Fourth item
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>
- First item
- Second item
- Third item
- Fourth item
無序清單
要建立無序清單,在行項目前加上破折號 (-)、星號 (*) 或加號 (+)。
- Second item
- Third item
- Fourth item
<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
程式碼
要將單字或片語標為程式碼,以反引號 (`) 包住。
At the command prompt, type nano.
程式碼區塊
要建立程式碼區塊,將區塊每行至少縮排四個空格或一個 Tab,或在區塊前後使用三個反引號 (```)。
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
```
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}水平線
要建立水平線,單獨一行使用三個以上星號 (***)、破折號 (---) 或底線 (___)。
連結
要建立連結,將連結文字放在方括號內(如 [Duck Duck Go]),緊接在後於括號內加上 URL(如 (https://duckduckgo.com))。
My favorite search engine is Duck Duck Go.
加入標題
可選擇性為連結加入標題。使用者滑鼠懸停時會顯示為工具提示。在 URL 後以引號包住標題即可。
My favorite search engine is Duck Duck Go.
圖片
要加入圖片,先加驚嘆號 (!),接著方括號內的替代文字,以及括號內的圖片路徑或 URL。可選擇性在路徑或 URL 後以引號加入標題。

跳脫字元
要顯示在 Markdown 中本用於格式化文字的字元,在該字元前加上反斜線 (\)。
* 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 |
表格
要加入表格,以三個以上連字號 (---) 建立每欄標題,以直線 (|) 分隔各欄。可選擇性在表格兩端加直線。
| --------- | ----------- |
| Header | Title |
| Paragraph | Text |
| Syntax | Description |
|---|---|
| Header | Title |
| Paragraph | Text |
對齊
在標題列連字號左側、右側或兩側加冒號 (:) 可將欄內文字左對齊、右對齊或置中。
| :--- | :---: | ---: |
| This | This | This |
| column | column | column |
| will | will | will |
| align | align | align |
| left | center | right |
| 左對齊 | 置中 | 右對齊 |
|---|---|---|
| This | This | This |
| column | column | column |
| will | will | will |
| align | align | align |
| left | center | right |