Markdown基础

Markdown基础

本文介绍了Markdown的概貌和感觉。 Markdown语法才是Markdown的详细文档,但是Markdown应该很容易就用起来,只要看几个例子就够了。 本文中的每个例子都给出了Markdown的写法,及其转换后的HTML代码。

如果只是想简单地尝试一下Markdown,Dingus是一个不错的去处。

段落,标题,引文

若干连续的行(之间没有空白行分开)构成一个段落,段落之间由若干空白行分开。 (空白行指的是空行,或者只有空白字符的行,比如空格符,跳格符等)一个正常的段落不应该用空格或跳格进行缩进。

Markdown有两种风格的标题:Setext和atx。 Setext风格把等号(=)和连字符(-)当“下划线”用,分别表示<h1><h2>。 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

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.

都会生成:

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

有序号列表直接用数字加点号(.)

Markdown:

1. Red
2. Green
3. Blue

HTML:

<ol>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ol>

你可以通过在列表项之间插入空白行,把列表项文本放入<p>标签。你可以通过缩进(4个空格符或1个跳格符)编写多段落的列表项。

Markdown:

* 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支持两种风格的链接:inline和reference。在两种风格下,你都需要用方括号([ ])来标示要转化为链接的文本。

inline风格使用紧跟在链接文本后面的圆括号(( ))。例如:

This is an [example link](http://example.com/).

HTML:

<p>This is an <a href="http://example.com/">example link</a>.</p>

另外,你还可以在圆括号中提供标题属性:

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>

reference风格可以用名字引用链接,然后在别处定义该链接:

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>

标题属性是可选的。链接名可以包含字符、数字和空格,但对大小写不敏感:

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>

图片

图片和链接很像。

inline风格(标题属性是可选的):

![alt text](/path/to/img.jpg "Title")

reference风格:

![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 `&mdash;`
instead of decimal-encoded entites like `&#8212;`.

HTML:

<p>I strongly recommend against using any
<code>&lt;blink&gt;</code> tags.</p>

<p>I wish SmartyPants used named entities like
<code>&amp;mdash;</code> instead of decimal-encoded
entites like <code>&amp;#8212;</code>.</p>

可以用缩进(4个空格符或1个跳格符)标示一个代码块。其中的与号(&)和尖括号(< >)会自动转化为对应的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>&lt;blockquote&gt;
    &lt;p&gt;For example.&lt;/p&gt;
&lt;/blockquote&gt;
</code></pre>

转载于:https://www.cnblogs.com/whgcompt/p/4563514.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值