Markdown: Basics (快速入門)

Getting the Gist of Markdown's Formatting Syntax

此頁提供了 Markdown 的簡單概念, 語法說明 頁提供了完整詳細(xì)的文檔,說明了每項(xiàng)功能。但是 Markdown 其實(shí)很簡單就可以上手,此頁文檔提供了一些范例,并且每個(gè)范例都會(huì)提供輸出的 HTML 結(jié)果。
其實(shí)直接試試看也是一個(gè)很不錯(cuò)的方法, Dingus 是一個(gè)網(wǎng)頁應(yīng)用程序,你可以把自已編寫的 Markdown 文檔轉(zhuǎn)成 XHTML。

段落、標(biāo)題、區(qū)塊代碼

一個(gè)段落是由一個(gè)以上的連接的行句組成,而一個(gè)以上的空行則會(huì)劃分出不同的段落(空行的定義是顯示上看起來像是空行,就被視為空行,例如有一行只有空白和 tab,那該行也會(huì)被視為空行),一般的段落不需要用空白或換行縮進(jìn)。
Markdown 支持兩種標(biāo)題的語法,Setextatx 形式。Setext 形式是用底線的形式,利用 =
(最高階標(biāo)題)和 -
(第二階標(biāo)題),Atx 形式在行首插入 1 到 6 個(gè) #
,對(duì)應(yīng)到標(biāo)題 1 到 6 階。
區(qū)塊引用則使用 email 形式的 '>
' 角括號(hào)。

Markdown 語法: `

   A First Level Header
   ====================
   A Second Level Header
   ---------------------
 Now is the time for all good men to come tothe aid of their country. This is just aregular paragraph.
 The quick brown fox jumped over the lazydog's back.
 ### Header 3
 >This is a blockquote.
 >
 > This is the second paragraph in the blockquote.
 >
 >## This is an H2 in a blockquote`

輸出 HTML 為:

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

修辭和強(qiáng)調(diào)

Markdown 使用星號(hào)和底線來標(biāo)記需要強(qiáng)調(diào)的區(qū)段。

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__.

輸出 HTML 為:

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

列表

無序列表使用星號(hào)、加號(hào)和減號(hào)來做為列表的項(xiàng)目標(biāo)記,這些符號(hào)是都可以使用的,使用星號(hào):
* Candy.
* Gum.
* Booze.

加號(hào):
+ Candy.
+ Gum.
+ Booze.

和減號(hào)
- Candy.
- Gum.
- Booze.

都會(huì)輸出 HTML 為:

    <ul>
    <li>Candy.</li>
    <li>Gum.</li>
    <li>Booze.</li>
    </ul>

有序的列表則是使用一般的數(shù)字接著一個(gè)英文句點(diǎn)作為項(xiàng)目標(biāo)記:

    1. Red
    2. Green
    3. Blue

輸出 HTML 為:

    <ol>
    <li>Red</li>
    <li>Green</li>
    <li>Blue</li>
    </ol>
如果你在項(xiàng)目之間插入空行,那項(xiàng)目的內(nèi)容會(huì)用 <p>包起來,你也可以在一個(gè)項(xiàng)目內(nèi)放上多個(gè)段落, 只要在它前面縮排 4 個(gè)空白或 1 個(gè) 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 支援兩種形式的鏈接語法: 行內(nèi)參考 兩種形式,兩種都是使用角括號(hào)來把文字轉(zhuǎn)成連結(jié)。
行內(nèi)形式是直接在后面用括號(hào)直接接上鏈接:
    This is an [example link](http://example.com/).

輸出 HTML 為:

    <p>This is an <a >example link</a>.</p>
你也可以選擇性的加上 title 屬性:
    This is an [example link](http://example.com/ "With a Title").
輸出 HTML 為:
    <p>This is an <a  title="With a Title">example link</a>.</p>
參考形式的鏈接讓你可以為鏈接定一個(gè)名稱,之后你可以在文件的其他地方定義該鏈接的內(nèi)容:
    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 
    title="Google">Google</a> than from <a 
    title="Yahoo Search">Yahoo</a> or <a 
    title="MSN Search">MSN</a>.</p>
title 屬性是選擇性的,鏈接名稱可以用字母、數(shù)字和空格,但是不分大小寫:
    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 >The New York Times</a>.
    </p>

圖片

圖片的語法和鏈接很像。
行內(nèi)形式(title 是選擇性的):
    ![](/path/to/img.jpg "Title")
參考形式:
   ![alt text][id][id]: /path/to/img.jpg "Title"
上面兩種方法都會(huì)輸出 HTML 為:
  ![](/path/to/img.jpg)

代碼

在一般的段落文字中,你可以使用反引號(hào) `來標(biāo)記代碼區(qū)段,區(qū)段內(nèi)的 &、<和 >都會(huì)被自動(dòng)的轉(zhuǎn)換成 HTML 實(shí)體,這項(xiàng)特性讓你可以很容易的在代碼區(qū)段內(nèi)插入 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>—
    </code> instead of decimal-encodedentites like <code>—</code>.
    </p>
如果要建立一個(gè)已經(jīng)格式化好的代碼區(qū)塊,只要每行都縮進(jìn) 4 個(gè)空格或是一個(gè) tab 就可以了,而 &、< 和 > 也一樣會(huì)自動(dòng)轉(zhuǎn)成 HTML 實(shí)體。
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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容