Markdown 学习笔记: Basics
Markdown 学习笔记: Basics##
原文:Basics.
了解Markdown格式化句法的要点###
本页对如何使用Markdown提供了一个简单的概述。在“句法”页中对Markdown的所有特性提供了完整的,包含细节的文档。但Markdown应该仅通过浏览几个简单的例子就可以开始使用。本页中的这些例子写成了之前/之后的形式,展示出了Markdown的句法和对应的HTML输出。
另一个有用的方法就是试用下Markdown。Dingus是一个可以输入Markdown格式文本并转换成XHTML格式的web应用。
段落,标题和块引用###
一个段落就是一行或多行连续的文本,由一行或多行空白行分隔开。(空白行可以是任何看起来空白的行,可以包含多个空格或制表符。)普通的段落不应该用空格或制表符缩进。
Markdown提供了两种风格的标题:Setext和atx。用于<h1
>和<h2
>标签的Setext风格标题,是通过在文字下方分别用等号或连字符实现的。而要实现atx风格的标题,是在行首放置1-6个#号,#号的数量等同于HTML标题的级别。
块引用是用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
Output:
<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__.
Output:
<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.
都会产生同样的输出:
<ul>
<li>Candy.</li>
<li>Gum.</li>
<li>Booze.</li>
</ul>
有序的列表用数字加上句号作为列表标记。如下:
1. Red
2. Green
3. Blue
输出为:
<ol>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ol>
如果你在列表项之间插入空白行,生成的文本中会有<p
>标签。你可以通过在你段落前用四个空格或者一个制表符缩进来制造多段的列表项。
* A list item.
With multiple paragraphs.
* Another item in the list.
输出:
<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/).
输出:
<p>This is an <a href="http://example.com/">
example link</a>.</p>
可选的,你可以在圆括号中包含一个标题参数:
This is an [example link](http://example.com/ "With a Title").
输出:
<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"
输出:
<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>
标题属性是可选的。链接名称可以包含字母,数字或者空格,但不是大小写敏感的。
I start my morning with a cup of coffee and
[The New York Times][NY Times].
[ny times]: http://www.nytimes.com/
输出:
<p>I start my morning with a cup of coffee and
<a href="http://www.nytimes.com/">The New York Times</a>.</p>
图片###
图片句法同引用句法很相像。
内联的(标题可选):
![alt text](/path/to/img.jpg "Title")
引用风格:
![alt text][id]
[id]: /path/to/img.jpg "Title"
上面两个例子会产生同样的输出:
<img src="/path/to/img.jpg" alt="alt text" title="Title" />
代码###
在通常的段落中,你可以通过将文本包含在重音符`中来产生代码段。任何&符号或角括号会自动转换成HTML实体。这使得用Markdown写HTML的实例代码非常容易。
I strongly recommend against using any `<blink>` tags.
I wish SmartyPants used named entities like `—`
instead of decimal-encoded entites like `—`.
输出:
<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>
要指定一段格式化的代码,将代码块的每行用四个空格或一个制表符缩进。同重音符产生的代码段一样,&
等特殊字符也会被自动跳过。
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>
输出:
<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>