` tags in the HTML output. For example, this input:
如果清單項目間用空行分開, Markdown 會把項目的內容在輸出時用 `
It's worth noting that it's possible to trigger an ordered list by
accident, by writing something like this:
當然,項目清單很可能會不小心產生,像是下面這樣的寫法:
1986. What a great season.
In other words, a *number-period-space* sequence at the beginning of a
line. To avoid this, you can backslash-escape the period:
換句話說,也就是在行首出現 *數字-句點-空白* ,要避免這樣的狀況,你
可以在句點前面加上反斜線。
1986\. What a great season.
Code Blocks
Pre-formatted code blocks are used for writing about programming or
markup source code. Rather than forming normal paragraphs, the lines
of a code block are interpreted literally. Markdown wraps a code block
in both `` and `` tags.
和程式相關的寫作或是標籤語言原始碼通常會有已經排版好的程式碼區塊,通常這些
區塊我們並不希望它照一般段落文件的方式去排版,而是照原來的樣子顯示,Markdown
會用 `` 和 `` 標籤來把程式碼區塊包起來。
To produce a code block in Markdown, simply indent every line of the
block by at least 4 spaces or 1 tab. For example, given this input:
在 Markdown 中要建立程式碼區塊很簡單,只要簡單的縮排 4 個空白或是 1 個 tab 就可以,
例如,下面的輸入:
This is a normal paragraph:
This is a code block.
Markdown will generate:
Markdown 會轉換成:
This is a normal paragraph:
This is a code block.
One level of indentation -- 4 spaces or 1 tab -- is removed from each
line of the code block. For example, this:
這個每行一階的縮排(4 個空白或是 1 個 tab),都會被移除,例如:
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
will turn into:
會被轉換為:
Here is an example of AppleScript:
tell application "Foo"
beep
end tell
A code block continues until it reaches a line that is not indented
(or the end of the article).
一個程式碼區塊會一直持續到碰到沒有縮排的行(或是文件結尾)。
Within a code block, ampersands (`&`) and angle brackets (`<` and `>`)
are automatically converted into HTML entities. This makes it very
easy to include example HTML source code using Markdown -- just paste
it and indent it, and Markdown will handle the hassle of encoding the
ampersands and angle brackets. For example, this:
在程式碼區塊裡面, `&` 、 `<` 和 `>` 會自動轉成 HTML 實體,這樣的方式會讓
你非常容易使用 Markdown 插入範例用的 HTML 原始碼,只需要複製貼上,然後縮
排就可以了,剩下的 Markdown 都會幫你處理,例如:
will turn into:
會被轉換為:
<div class="footer">
© 2004 Foo Corporation
</div>
Regular Markdown syntax is not processed within code blocks. E.g.,
asterisks are just literal asterisks within a code block. This means
it's also easy to use Markdown to write about Markdown's own syntax.
程式碼區塊中,一般的 Markdown 語法不會被轉換,像是星號就只會是星號,
這表示你可以很容易用 Markdown 語法寫 Markdown 語法相關的文件。
Horizontal Rules
You can produce a horizontal rule tag (`
`) by placing three or
more hyphens, asterisks, or underscores on a line by themselves. If you
wish, you may use spaces between the hyphens or asterisks. Each of the
following lines will produce a horizontal rule:
你可以用在一行內用三個或以上的星號、減號、底線來建立一個分隔線,
行內不能有其他東西,你也可以在星號中間插入空白,下面每種寫法都可
以建立分隔線:
* * *
***
*****
- - -
---------------------------------------
* * *
Span Elements
Links
Markdown supports two style of links: *inline* and *reference*.
Markdown 支援兩種形式的連結語法: *行內* 和 *參考* 兩種形式。
In both styles, the link text is delimited by [square brackets].
不管是哪一種,連結的文字都是用 [方括號] 來標記。
To create an inline link, use a set of regular parentheses immediately
after the link text's closing square bracket. Inside the parentheses,
put the URL where you want the link to point, along with an *optional*
title for the link, surrounded in quotes. For example:
要建立一個行內形式的連結,只要在方塊括號後面馬上接著括號並插入網址連結即可,
如果你還想要加上連結的 title 文字,只要在網址後面,用雙引號把 title 文字
包起來即可,例如:
This is [an example](http://example.com/ "Title") inline link.
[This link](http://example.net/) has no title attribute.
Will produce:
會產生:
This is
an example inline link.
This link has no
title attribute.
If you're referring to a local resource on the same server, you can
use relative paths:
如果你是要連結到同樣主機的資源,你可以使用相對路徑:
See my [About](/about/) page for details.
Reference-style links use a second set of square brackets, inside
which you place a label of your choosing to identify the link:
參考形式的連結使用另外一個方括號接在連結文字的括號後面,而在第二個方括號
裡面要填入連結的辨識用的標籤:
This is [an example][id] reference-style link.
You can optionally use a space to separate the sets of brackets:
你也可以選擇性的在兩個方括號中間加上空白:
This is [an example] [id] reference-style link.
Then, anywhere in the document, you define your link label like this,
on a line by itself:
接著,在文件的任意處,你可以把這個標籤的連結內容定義出來:
[id]: http://example.com/ "Optional Title Here"
That is:
連結定義的形式為:
* Square brackets containing the link identifier (optionally
indented from the left margin using up to three spaces);
* followed by a colon;
* followed by one or more spaces (or tabs);
* followed by the URL for the link;
* optionally followed by a title attribute for the link, enclosed
in double or single quotes, or enclosed in parentheses.
* 方括號,裡面輸入連結的辨識用標籤
* 接著一個分號
* 接著一個以上的空白或 tab
* 接著連結的網址
* 選擇性的接著 title 內容,可以用單引號、雙引號或是括弧包著
The following three link definitions are equivalent:
下面這三種連結的定義都是相同:
[foo]: http://example.com/ "Optional Title Here"
[foo]: http://example.com/ 'Optional Title Here'
[foo]: http://example.com/ (Optional Title Here)
**Note:** There is a known bug in Markdown.pl 1.0.1 which prevents
single quotes from being used to delimit link titles.
**Note:** 有一個已知的問題是 Markdown.pl 1.0.1 會忽略單引號包起來的
連結 title。
The link URL may, optionally, be surrounded by angle brackets:
連結網址也可以用角括號包起來:
[id]: "Optional Title Here"
You can put the title attribute on the next line and use extra spaces
or tabs for padding, which tends to look better with longer URLs:
你也可以把 title 屬性放到下一行,也可以加一些縮排,網址太長的話,這樣
會比較好看:
[id]: http://example.com/longish/path/to/resource/here
"Optional Title Here"
Link definitions are only used for creating links during Markdown
processing, and are stripped from your document in the HTML output.
網址定義只有在產生連結的時候用到,並不會直接出現在文件之中。
Link definition names may consist of letters, numbers, spaces, and
punctuation -- but they are *not* case sensitive. E.g. these two
links:
連結辨識標籤可以有字母、數字、空白和標點符號,但是並 *不* 分大小寫,
因此下面兩個連結是一樣的:
[link text][a]
[link text][A]
are equivalent.
The *implicit link name* shortcut allows you to omit the name of the
link, in which case the link text itself is used as the name.
Just use an empty set of square brackets -- e.g., to link the word
"Google" to the google.com web site, you could simply write:
[Google][]
And then define the link:
[Google]: http://google.com/
Because link names may contain spaces, this shortcut even works for
multiple words in the link text:
Visit [Daring Fireball][] for more information.
And then define the link:
[Daring Fireball]: http://daringfireball.net/
Link definitions can be placed anywhere in your Markdown document. I
tend to put them immediately after each paragraph in which they're
used, but if you want, you can put them all at the end of your
document, sort of like footnotes.
Here's an example of reference links in action:
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"
Using the implicit link name shortcut, you could instead write:
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"
Both of the above examples will produce the following HTML output:
I get 10 times more traffic from Google than from
Yahoo
or MSN.
For comparison, here is the same paragraph written using
Markdown's inline link style:
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").
The point of reference-style links is not that they're easier to
write. The point is that with reference-style links, your document
source is vastly more readable. Compare the above examples: using
reference-style links, the paragraph itself is only 81 characters
long; with inline-style links, it's 176 characters; and as raw HTML,
it's 234 characters. In the raw HTML, there's more markup than there
is text.
With Markdown's reference-style links, a source document much more
closely resembles the final output, as rendered in a browser. By
allowing you to move the markup-related metadata out of the paragraph,
you can add links without interrupting the narrative flow of your
prose.
Emphasis
Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
emphasis. Text wrapped with one `*` or `_` will be wrapped with an
HTML `` tag; double `*`'s or `_`'s will be wrapped with an HTML
`` tag. E.g., this input:
*single asterisks*
_single underscores_
**double asterisks**
__double underscores__
will produce:
single asterisks
single underscores
double asterisks
double underscores
You can use whichever style you prefer; the lone restriction is that
the same character must be used to open and close an emphasis span.
Emphasis can be used in the middle of a word:
un*frigging*believable
But if you surround an `*` or `_` with spaces, it'll be treated as a
literal asterisk or underscore.
To produce a literal asterisk or underscore at a position where it
would otherwise be used as an emphasis delimiter, you can backslash
escape it:
\*this text is surrounded by literal asterisks\*
Code
To indicate a span of code, wrap it with backtick quotes (`` ` ``).
Unlike a pre-formatted code block, a code span indicates code within a
normal paragraph. For example:
Use the `printf()` function.
will produce:
Use the printf()
function.
To include a literal backtick character within a code span, you can use
multiple backticks as the opening and closing delimiters:
``There is a literal backtick (`) here.``
which will produce this:
There is a literal backtick (`) here.
The backtick delimiters surrounding a code span may include spaces --
one after the opening, one before the closing. This allows you to place
literal backtick characters at the beginning or end of a code span:
A single backtick in a code span: `` ` ``
A backtick-delimited string in a code span: `` `foo` ``
will produce:
A single backtick in a code span: `
A backtick-delimited string in a code span: `foo`
With a code span, ampersands and angle brackets are encoded as HTML
entities automatically, which makes it easy to include example HTML
tags. Markdown will turn this:
Please don't use any `