NOTE: This is Traditional Chinese Edition Document of Markdown Syntax. If you are seeking for English Edition Document. Please refer to Markdown: Syntax.
注意
Markdown 的目標是實現
不過最需要強調的便是它的可讀性
因此 Markdown
的語法全由標點符號所組成
Markdown
的語法有個主要的目的
Markdown 不是要來取代
HTML
不在 Markdown 涵蓋範圍之外的標籤
只有區塊元素 ──
比如<div>
<table>
<pre>
<p>
等標籤<p>
標籤
舉例來說
This is a regular paragraph.
<table>
<tr>
<td>Foo</td>
</tr>
</table>
This is another regular paragraph.
請注意*強調*
HTML
的區段標籤如<span>
<cite>
<del>
則不受限制<a>
或<img>
標籤
HTML 區段標籤和區塊標籤不同
在 HTML
文件中<
和&
<
符號用於起始標籤&
符號則用於標記
HTML
實體<
&
&
符號其實很容易讓寫作網路文件的人感到困擾AT&T
&
符號
http://images.google.com/images?num=30&q=larry+bird
你必須要把網址轉成
http://images.google.com/images?num=30&q=larry+bird
才能放到連結標籤的href
Markdown
允許你直接使用這些符號&
符號的話&
©
Markdown 將不會對這段文字做修改
AT&T
Markdown 就會將它轉為
AT&T
類似的狀況也會發生在<
符號上<
符號作為 HTML
標籤使用
4 < 5
Markdown 將會把它轉換為
4 < 5
不過需要注意的是<
和&
兩個符號都一定會被轉換成
HTML 實體<
和&
都轉換為 HTML
實體
一個段落是由一個以上相連接的行句組成
<br />
標籤
如果你真的想要插入<br />
標籤的話
是的<br />
<br />
Markdown 支援兩種標題的語法
Setext
形式是用底線的形式=
-
This is an H1
=============
This is an H2
-------------
任何數量的=
和-
都可以有效果
Atx 形式則是在行首插入 1 到 6 個#
# This is an H1
## This is an H2
###### This is an H6
你可以選擇性地#
#
數量也不用和開頭一樣
# This is an H1 #
## This is an H2 ##
### This is an H3 ######
Markdown 使用 email 形式的區塊引言>
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
>
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.
Markdown
也允許你只在整個段落的第一行最前面加上>
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.
區塊引言可以有階層>
> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.
引言的區塊內也可以使用其他的 Markdown
語法
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
任何標準的文字編輯器都能簡單地建立 email 樣式的引言
Markdown 支援有序清單和無序清單
無序清單使用星號
* Red
* Green
* Blue
等同於
+ Red
+ Green
+ Blue
也等同於
- Red
- Green
- Blue
有序清單則使用數字接著一個英文句點
1. Bird
2. McHale
3. Parish
很重要的一點是
<ol>
<li>Bird</li>
<li>McHale</li>
<li>Parish</li>
</ol>
如果你的清單標記寫成
1. Bird
1. McHale
1. Parish
或甚至是
3. Bird
1. McHale
8. Parish
你都會得到完全相同的 HTML 輸出
如果你使用懶惰的寫法
清單項目標記通常是放在最左邊
要讓清單看起來更漂亮
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
但是如果你很懶
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
如果清單項目間用空行分開<p>
標籤包起來
* Bird
* Magic
會被轉換為
<ul>
<li>Bird</li>
<li>Magic</li>
</ul>
但是這個
* Bird
* Magic
會被轉換為
<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>
清單項目可以包含多個段落
1. This is a list item with two paragraphs. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit. Aliquam hendrerit
mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet
vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
sit amet velit.
2. Suspendisse id sem consectetuer libero luctus adipiscing.
如果你每行都有縮排
* This is a list item with two paragraphs.
This is the second paragraph in the list item. You're
only required to indent the first line. Lorem ipsum dolor
sit amet, consectetuer adipiscing elit.
* Another item in the same list.
如果要在清單項目內放進引言>
就需要縮排
* A list item with a blockquote:
> This is a blockquote
> inside a list item.
如果要放程式碼區塊的話
* A list item with a code block:
<code goes here>
當然
1986. What a great season.
換句話說
1986\. What a great season.
和程式相關的寫作或是標籤語言原始碼通常會有已經排版好的程式碼區塊<pre>
和<code>
標籤來把程式碼區塊包起來
要在 Markdown 中建立程式碼區塊很簡單
This is a normal paragraph:
This is a code block.
Markdown 會轉換成
<p>This is a normal paragraph:</p>
<pre><code>This is a code block.
</code></pre>
這個每行一階的縮排
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
會被轉換為
<p>Here is an example of AppleScript:</p>
<pre><code>tell application "Foo"
beep
end tell
</code></pre>
一個程式碼區塊會一直持續到沒有縮排的那一行
在程式碼區塊裡面&
<
和>
會自動轉成
HTML 實體
<div class="footer">
© 2004 Foo Corporation
</div>
會被轉換為
<pre><code><div class="footer">
&copy; 2004 Foo Corporation
</div>
</code></pre>
程式碼區塊中
你可以在一行中用三個或以上的星號
* * *
***
*****
- - -
---------------------------------------
Markdown
支援兩種形式的連結語法
不管是哪一種
要建立一個行內形式的連結
This is [an example](http://example.com/ "Title") inline link.
[This link](http://example.net/) has no title attribute.
會產生
<p>This is <a href="http://example.com/" title="Title">
an example</a> inline link.</p>
<p><a href="http://example.net/">This link</a> has no
title attribute.</p>
如果你是要連結到同樣主機的資源
See my [About](/about/) page for details.
參考形式的連結使用另外一個方括號接在連結文字的括號後面
This is [an example][id] reference-style link.
你也可以選擇性地在兩個方括號中間加上空白
This is [an example] [id] reference-style link.
接著
[id]: http://example.com/ "Optional Title Here"
連結定義的形式為
下面這三種連結的定義都是相同
[foo]: http://example.com/ "Optional Title Here"
[foo]: http://example.com/ 'Optional Title Here'
[foo]: http://example.com/ (Optional Title Here)
請注意
連結網址也可以用角括號包起來
[id]: <http://example.com/> "Optional Title Here"
你也可以把 title
屬性放到下一行
[id]: http://example.com/longish/path/to/resource/here
"Optional Title Here"
網址定義只有在產生連結的時候用到
連結辨識標籤可以有字母
[link text][a]
[link text][A]
預設的連結標籤功能讓你可以省略指定連結標籤
[Google][]
然後定義連結內容
[Google]: http://google.com/
由於連結文字可能包含空白
Visit [Daring Fireball][] for more information.
然後接著定義連結
連結的定義可以放在文件中的任何一個地方
下面是一個參考式連結的範例
I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].
[1]: http://google.com/ "Google"
[2]: http://search.yahoo.com/ "Yahoo Search"
[3]: http://search.msn.com/ "MSN Search"
如果改成用連結名稱的方式寫
I get 10 times more traffic from [Google][] than from
[Yahoo][] or [MSN][].
[google]: http://google.com/ "Google"
[yahoo]: http://search.yahoo.com/ "Yahoo Search"
[msn]: http://search.msn.com/ "MSN Search"
上面兩種寫法都會產生下面的 HTML
<p>I get 10 times more traffic from <a href="http://google.com/"
title="Google">Google</a> than from
<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
下面是用行內形式寫的同樣一段內容的 Markdown
文件
I get 10 times more traffic from [Google](http://google.com/ "Google")
than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
[MSN](http://search.msn.com/ "MSN Search").
參考式的連結其實重點不在於它比較好寫
使用 Markdown
的參考式連結
Markdown
使用星號*
_
*
或_
包圍的字詞會被轉成用<em>
標籤包圍*
或_
包起來的話<strong>
*single asterisks*
_single underscores_
**double asterisks**
__double underscores__
會轉成
<em>single asterisks</em>
<em>single underscores</em>
<strong>double asterisks</strong>
<strong>double underscores</strong>
你可以隨便用你喜歡的樣式
強調也可以直接插在文字中間
un*frigging*believable
但是如果你的 *
和 _
兩邊都有空白的話
如果要在文字前後直接插入普通的星號或底線
\*this text is surrounded by literal asterisks\*
如果要標記一小段行內程式碼`
Use the `printf()` function.
會產生
<p>Use the <code>printf()</code> function.</p>
如果要在程式碼區段內插入反引號
``There is a literal backtick (`) here.``
這段語法會產生
<p><code>There is a literal backtick (`) here.</code></p>
程式碼區段的起始和結束端都可以放入一個空白
A single backtick in a code span: `` ` ``
A backtick-delimited string in a code span: `` `foo` ``
會產生
<p>A single backtick in a code span: <code>`</code></p>
<p>A backtick-delimited string in a code span: <code>`foo`</code></p>
在程式碼區段內&
和角括號都會被轉成 HTML
實體
Please don't use any `<blink>` tags.
轉為
<p>Please don't use any <code><blink></code> tags.</p>
你也可以這樣寫
`—` is the decimal-encoded equivalent of `—`.
以產生
<p><code>&#8212;</code> is the decimal-encoded
equivalent of <code>&mdash;</code>.</p>
很明顯地
Markdown
使用一種和連結很相似的語法來標記圖片
行內圖片的語法看起來像是


詳細敘述如下
!
參考式的圖片語法則長得像這樣
![Alt text][id]
[id]: url/to/image "Optional title attribute"
到目前為止<img>
標籤
Markdown
支援比較簡短的自動連結形式來處理網址和電子郵件信箱
<http://example.com/>
Markdown 會轉為
<a href="http://example.com/">http://example.com/</a>
自動的郵件連結也很類似
<address@example.com>
Markdown 會轉成
<a href="mailto:addre
ss@example.co
m">address@exa
mple.com</a>
在瀏覽器裡面
Markdown
可以利用反斜線來插入一些在語法中有其他意義的符號<em>
標籤
\*literal asterisks\*
Markdown 支援在下面這些符號前面加上反斜線來幫助插入普通的符號
\ 反斜線
` 反引號
* 星號
_ 底線
{} 大括號
[] 方括號
() 括號
# 井字號
+ 加號
- 減號
. 英文句點
! 驚嘆號
感謝