此頁提供了 Markdown 的簡單概念, 語法說明 頁提供了完整詳細的文檔,說明了每項功能。可是 Markdown 其實很簡單就能夠上手,此頁文檔提供了一些範例,而且每一個範例都會提供輸出的 HTML 結果。html
其實直接試試看也是一個很不錯的方法, Dingus 是一個網頁應用程序,你能夠把自已編寫的 Markdown 文檔轉成 XHTML。git
一個段落是由一個以上的鏈接的行句組成,而一個以上的空行則會劃分出不一樣的段落(空行的定義是顯示上看起來像是空行,就被視爲空行,例若有一行只有空白和 tab,那該行也會被視爲空行),通常的段落不須要用空白或換行縮進。bash
Markdown 支持兩種標題的語法,Setext 和 atx 形式。Setext 形式是用底線的形式,利用 =
(最高階標題)和 -
(第二階標題),Atx 形式在行首插入 1 到 6 個 #
,對應到標題 1 到 6 階。markdown
區塊引用則使用 email 形式的 ‘>
‘ 角括號。ui
Markdown 語法:google
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 複製代碼
輸出 HTML 爲:spa
<h1>A First Level Header</h1>
<h2>A Second Level Header</h2>
<p>Now is the time for all good men to come to
the aid of their country. This is just a
regular paragraph.</p>
<p>The quick brown fox jumped over the lazy
dog's back.</p> <h3>Header 3</h3> <blockquote> <p>This is a blockquote.</p> <p>This is the second paragraph in the blockquote.</p> <h2>This is an H2 in a blockquote</h2> </blockquote> 複製代碼
Markdown 使用星號和底線來標記須要強調的區段。.net
Markdown 語法:code
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__.
複製代碼
輸出 HTML 爲:orm
<p>Some of these words <em>are emphasized</em>.
Some of these words <em>are emphasized also</em>.</p>
<p>Use two asterisks for <strong>strong emphasis</strong>.
Or, if you prefer, <strong>use two underscores instead</strong>.</p>
複製代碼
無序列表使用星號、加號和減號來作爲列表的項目標記,這些符號是均可以使用的,使用星號:
* Candy.
* Gum.
* Booze.
複製代碼
加號:
+ Candy.
+ Gum.
+ Booze.
複製代碼
和減號
- Candy.
- Gum.
- Booze.
複製代碼
都會輸出 HTML 爲:
<ul>
<li>Candy.</li>
<li>Gum.</li>
<li>Booze.</li>
</ul>
複製代碼
有序的列表則是使用通常的數字接着一個英文句點做爲項目標記:
1. Red
2. Green
3. Blue
複製代碼
輸出 HTML 爲:
<ol>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ol>
複製代碼
若是你在項目之間插入空行,那項目的內容會用 <p>
包起來,你也能夠在一個項目內放上多個段落,只要在它前面縮排 4 個空白或 1 個 tab 。
* A list item.
With multiple paragraphs.
* Another item in the list.
複製代碼
輸出 HTML 爲:
<ul>
<li><p>A list item.</p>
<p>With multiple paragraphs.</p></li>
<li><p>Another item in the list.</p></li>
</ul>
複製代碼
Markdown 支援兩種形式的連接語法:
行內形式是直接在後面用括號直接接上連接:
This is an [example link](http://example.com/).
複製代碼
輸出 HTML 爲:
<p>This is an <a href="http://example.com/">
example link</a>.</p>
複製代碼
你也能夠選擇性的加上 title 屬性:
This is an [example link](http://example.com/ "With a Title").
複製代碼
輸出 HTML 爲:
<p>This is an <a href="http://example.com/" title="With a Title">
example link</a>.</p>
複製代碼
參考形式的連接讓你能夠爲連接定一個名稱,以後你能夠在文件的其餘地方定義該連接的內容:
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"
複製代碼
輸出 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>
複製代碼
title 屬性是選擇性的,連接名稱能夠用字母、數字和空格,可是不分大小寫:
I start my morning with a cup of coffee and
[The New York Times][NY Times].
[ny times]: http://www.nytimes.com/
複製代碼
輸出 HTML 爲:
<p>I start my morning with a cup of coffee and
<a href="http://www.nytimes.com/">The New York Times</a>.</p>
複製代碼
圖片的語法和連接很像。
行內形式(title 是選擇性的):
![alt text](/path/to/img.jpg "Title")
複製代碼
參考形式:
![alt text][id]
[id]: /path/to/img.jpg "Title"
複製代碼
上面兩種方法都會輸出 HTML 爲:
<img src="/path/to/img.jpg" alt="alt text" title="Title" />
複製代碼
在通常的段落文字中,你可使用反引號 `
來標記代碼區段,區段內的 &
、<
和 >
都會被自動的轉換成 HTML 實體,這項特性讓你能夠很容易的在代碼區段內插入 HTML 碼:
I strongly recommend against using any `<blink>` tags.
I wish SmartyPants used named entities like `—`
instead of decimal-encoded entites like `—`.
複製代碼
輸出 HTML 爲:
<p>I strongly recommend against using any
<code><blink></code> tags.</p>
<p>I wish SmartyPants used named entities like
<code>&mdash;</code> instead of decimal-encoded
entites like <code>&#8212;</code>.</p>
複製代碼
若是要創建一個已經格式化好的代碼區塊,只要每行都縮進 4 個空格或是一個 tab 就能夠了,而 &
、<
和 >
也同樣會自動轉成 HTML 實體。
Markdown 語法:
If you want your page to validate under XHTML 1.0 Strict,
you've got to put paragraph tags in your blockquotes: <blockquote> <p>For example.</p> </blockquote> 複製代碼
輸出 HTML 爲:
<p>If you want your page to validate under XHTML 1.0 Strict,
you've got to put paragraph tags in your blockquotes:</p> <pre><code><blockquote> <p>For example.</p> </blockquote> </code></pre>複製代碼