Markdown 是一種輕量級的標記語言,由John Gruber和Aaron Swartz創建,使其成為可讀性最大并可再發行的可輸入輸出的格式。這種語言創建靈感來自于已經存在的帶標記的電子郵件文本。Markdown 允許 HTML 語法, 所以使用者如果需要可以直接用 HTML來表示是可以的。Markdown最初由Gruber應用在Perl語言中,但現在已經有多種編程語言應用了。它是開源項目,并以BSD-style許可證的許可方式以插件形式或內容管理系統形式發布。
背景介紹
上周準備將blog遷移至Github后,發現使用Jekyll+Markdown的方式撰寫靜態博客非常方便,但是,對于markdown的語法還沒有想過的學習,所以入手較慢,對于如何撰寫blog還是處于茫然階段,因此,這周學習了一下markdown的語法,并動手實踐了一把,感覺上手比較容易,不過要想熟練使用,還需要花費一定的時間來多多實踐。當然了,由于內容比較易讀,所以以后寫txt可以直接用markdown來寫,既可以鍛煉熟悉程度,又可以寫出帶有組織結構的文檔,不想word那么冗余。
工具
Windows下面,推薦使用MarkdownPad軟件進行撰寫。
Linux下面,推薦使用ReText軟件撰寫。
這兩款軟件都支持所見即所得,即撰寫后即可實時的看到轉化后的效果。
安裝過程
安裝python: http://www.python.org/ftp/python/2.7.2/python-2.7.2.msi
安裝markdown: http://pypi.python.org/packages/any/M/Markdown/Markdown-2.0.win32.exe
下載并安裝MarkdownPad:http://markdownpad.com/download/MarkdownPad.exe
在線轉化
Dingus:
http://daringfireball.net/projects/markdown/dingus Github:將markdown文檔上傳至Github后,可以直接看到效果,該文檔會自動被Github翻譯。另外,上面的工具還能夠支持將生成的文檔保存為pdf等格式。
學習筆記和入門語法(以Markdown語法來寫,達到練習目的):
Markdown Syntax:
1.Phrase Emphasis 斜體與加粗
*italic* **bold**
_italic_ __bold__
2.Links 超鏈接
方法1 Inline:
An [example](http://url.com/ "Title")
方法2 Reference-style labels (titles are optional):
An [example][id]
Then, anywhere else in the doc, define the link:
[id]: http://example.com/ "Title"
3.Images 插入圖片
方法1 Inline (titles are optional):

方法2 Reference-style:
![alt text][id]
[id]: /url/to/img.jpg "Title"
4.Headers 標題
方法1 Setext-style:
Header 1
========
Header 2
--------
方法2 atx-style (closing #'s are optional):
# Header 1 #
## Header 2 ##
###### Header 6
5.Lists 列表
有序列表 Ordered, without paragraphs:
1. Foo
2. Bar
無序列表 Unordered, with paragraphs:
* A list item.
With multiple paragraphs.
* Bar
You can nest them:
* Abacus
* answer
* Bubbles
1. bunk
2. bupkis
* BELITTLER
3. burper
* Cunning
6.Blockquotes 塊引用
> Email-style angle brackets
> are used for blockquotes.
> > And, they can be nested.
> #### Headers in blockquotes
>
> * You can quote a list.
> * Etc.
7.Code Spans 代碼段
`<code>` spans are delimited by backticks.
You can include literal backticks
like `` `this` ``.
Preformatted Code Blocks
Indent every line of a code block by at least 4 spaces or 1 tab.
This is a normal paragraph.
This is a preformatted
code block.
8.Horizontal Rules 水平分割線
Three or more dashes or asterisks:
---
* * *
- - - -
9.Manual Line Breaks 換行
End a line with two or more spaces:
Roses are red,
Violets are blue.
下面是另外一篇
============================
## Getting the Gist of Markdown's Formatting Syntax
此頁提供了 Markdown 的簡單概念, 語法說明 頁提供了完整詳細的文檔,說明了每項功能。但是 Markdown 其實很簡單就可以上手,此頁文檔提供了一些范例,并且每個范例都會提供輸出的 HTML 結果。
其實直接試試看也是一個很不錯的方法, Dingus 是一個網頁應用程序,你可以把自已編寫的 Markdown 文檔轉成 XHTML。
## 段落、標題、區塊代碼
一個段落是由一個以上的連接的行句組成,而一個以上的空行則會劃分出不同的段落(空行的定義是顯示上看起來像是空行,就被視為空行,例如有一行只有空白和 tab,那該行也會被視為空行),一般的段落不需要用空白或換行縮進。
Markdown 支持兩種標題的語法,Setext 和 atx 形式。Setext 形式是用底線的形式,利用 = (最高階標題)和 - (第二階標題),Atx 形式在行首插入 1 到 6 個 # ,對應到標題 1 到 6 階。
區塊引用則使用 email 形式的 '>' 角括號。
Markdown 語法:
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 為:
<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 使用星號和底線來標記需要強調的區段。
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>
## 列表
無序列表使用星號、加號和減號來做為列表的項目標記,這些符號是都可以使用的,使用星號:
* 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 >
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>
參考形式的鏈接讓你可以為鏈接定一個名稱,之后你可以在文件的其他地方定義該鏈接的內容:
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 屬性是選擇性的,鏈接名稱可以用字母、數字和空格,但是不分大小寫:
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>
## 圖片
圖片的語法和鏈接很像。
行內形式(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>
參考資料:
posted on 2012-06-17 19:16
deercoder 閱讀(8154)
評論(3) 編輯 收藏 引用 所屬分類:
讀書