Markdown 是一種輕量級標記語言,簡稱 md,創始人為約翰·格魯伯(John Gruber)。它讓人們「以易讀易寫的純文字格式撰寫文件,再轉換成有效的 XHTML 或 HTML」,並吸收了電子郵件中既有的純文字標記慣例。——維基百科
以下依個人使用習慣整理,分為「簡明語法」與「語法詳解」兩部分。
# 一級標題
## 二級標題
...
###### 六級標題
……
- 無序表列
1. 有序表列
> 引用內容
引用內容
**兩個星號是粗體**
*一個星號是斜體*
Hello World!
Hello World!
<https://hovertree.com/>
<hello@hovertree.com>
https://hovertree.com/
hello@hovertree.com
網址與信箱直接用角括號包起來,就會自動變成連結。
插入連結有兩種寫法:行內式與參考式。
[link text](https://hovertree.com/ "optional title")
[link text][id]
[id]: https://hovertree.com/ "optional title here"
行內式的連結文字內容。
參考式的[連結文字內容][id]
[id]: https://hovertree.com/ "optional title here"
插入圖片:

[![][jane-eyre-pic]{ImgCap}{/ImgCap}][jane-eyre-douban]
[jane-eyre-pic]: https://hovertree.com/hvtimg/bjafaj/9h2t2lm5.jpg
[jane-eyre-douban]: https://hovertree.com/jq/hovertreeimg/
如果段落開頭使用 Tab 縮排,會被視為程式碼區塊。
<php>
echo "hello world";
</php>
另一種寫法是用三個反引號加上語言名稱,例如 javascript、php、html 等。
行內程式碼則用單個反引號包起來:
Use the `printf()` function.
一行內放三個以上的星號、減號或底線即可建立分隔線;用兩個 ~ 包住文字可建立刪除線。
```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
function(){ alert('hello world!') }
標題除了用 #,也可以用「文字下方接一串等號或減號」的 Setext 風格:
A First Level Header
====================
A Second Level Header
---------------------
Now is the time for all good men to come to the aid of their country.
This is just a regular paragraph. The quick brown fox jumped over the
lazy dog's back.
### Header 3
> This is a blockquote.
>
> This is the second paragraph in the blockquote.
>
> ## This is an H2 in a blockquote
段落中的換行可以直接按 Enter。
這是一段引用。
引用中的第二行,需要 Enter 後另起一行再寫一個
>。在引用裡寫兩個 #,就成了引用中的二級標題
Markdown 使用星號與底線標記需要強調的段落:
Some of these words *are emphasized*.
Some of these words _are emphasized also_.
Use two asterisks for **strong emphasis**.
Or, if you prefer, __use two underscores instead__.
Some of these words are emphasized.
Some of these words are emphasized also.
Use two asterisks for strong emphasis.
Or, if you prefer, use two underscores instead.
無序表列可用星號、加號或減號,效果完全相同。
* Candy.
* Gum.
* Booze.
+ Candy.
+ Gum.
+ Booze.
- Candy.
- Gum.
- Booze.
有序表列則是數字接一個英文句點:
1. Red
2. Green
3. Blue
注意:若要在行內呈現「數字點」而不被解析成表列,可寫成 數字\. 的轉義形式。
Markdown 支援行內式與參考式兩種連結語法。
行內式:直接在後面用括號接上網址。
This is an [hovertree link](https://hovertree.com/).
也可以選擇性加上 title 屬性:
This is an [hovertree link](https://hovertree.com/ "With a Title").
滑鼠懸停時會顯示提示(視編輯器而定)。
參考式:先為連結取一個名稱,之後可在文件其他位置統一定義它的內容,適合同一個連結重複出現多次的情況。
I get 10 times more traffic from [HoverTree][1] than from [Keleyi][2] or [HoverClock][3].
[1]: https://hovertree.com/ "HoverTree"
[2]: https:/// "Keleyi"
[3]: https://hovertree.com/texiao/hoverclock/ "HoverClock"
圖片語法與連結幾乎相同,只是前面多一個驚嘆號。
行內式(title 為選填):
{ImgCap}{/ImgCap}
參考式:
![][id]{ImgCap}alt text{/ImgCap}
[id]: /path/to/img.jpg "Title"
在一般段落中,用反引號包住的就是程式碼區段。區段內的 &、<、> 會被自動轉換為 HTML 實體,所以你可以很輕鬆地在行內程式碼裡放 HTML 標籤而不會被瀏覽器解析:
I strongly recommend against using any `<blink>` tags.
I wish SmartyPants used named entities like `—` instead of
decimal-encoded entites like `—`.
若要建立已格式化的程式碼區塊,只要每一行都縮排 4 個空格或一個 Tab 即可,其中的 &、<、> 同樣會自動轉成 HTML 實體。