Markdown基本用法

作者 yellow river 日期 2017-09-05
Markdown基本用法

Markdown是一种轻量级的标记语言,相对于复杂的HTML标记语言来说,常用的标记符号不超过十个。
可以很方便地导出为PDF、HTML格式文件,使得使用者可以专心于码字,而无需花大量精力在排版上。

常用标签

段落

一个段落是由一个以上的连接的行句组成,而一个以上的空行则会划分出不同的段落(空行的定义是显示上看起来像是空行,就被视为空行,例如有一行只有空白和 tab,那该行也会被视为空行),一般的段落不需要用空白或换行缩进

Header — 标题

Markdown 支持两种标题的语法,Setext 和 atx 形式。

  • Setext 形式是用底线的形式,利用 = (最高阶标题)和 - (第二阶标题)
  • Atx 形式在行首插入 1 到 6 个 # ,对应到标题 1 到 6 阶。

1. markdown header写法

一级标题 or # 一级标题
=======
二级标题 or ## 二级标题
-------
### 三级标题
#### 四级标题 ...

2. HTML输出代码

<h1>一级标题</h1>
<h2>二级标题</h2>
<h3>三级标题</h3>

Blockquote — 块引用

1. 段落内容展示

This is a blockquote.
ps.段落中也可以增加标题,标题级数不相对继承

H4 in blockquote

2. markdown blockquote写法

> This is a blockquote.
>
> ps.段落中也可以增加标题,标题级数不相对继承
>#### H4 in blockquote

3. HTML输出代码

<blockquote>
<p>This is a blockquote.<br>ps.段落中也可以增加标题,标题级数不相对继承</p>
<h4>H4 in blockquote</h4>
</blockquote>

Highlight — 代码高亮

1. markdown highlight写法

```+语言名(比如java)
//代码内容
```

2. highlight展示

public static void main(String[] args){
System.out.println("abc")
}

支持语言参考:http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html

修辞和强调

Markdown 使用星号和底线来标记需要强调的区段。

1. 斜体&加粗

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.

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

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

List Item — 列表项

无序列表使用星号、加号和减号来做为列表的项目标记,这些符号是都可以使用的(效果相同),例如:

  • Candy.
  • Gum.
  • Booze.

1. markdown列表写法

使用星号:

* Candy.
* Gum.
* Booze.

加号:

+ Candy.
+ Gum.
+ Booze.

减号:

- Candy.
- Gum.
- Booze.

2. HTML输出代码

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

3. 切记!

列表元素下一行如果要跟标题(header),__一定要空行__,不然标题会被包在<li>标签里面,页面展示会产生大块空白。

行内链接

This is an example link.

1. markdown 行内链接写法

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

2. HTML输出代码

<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 than from
Yahoo or MSN.

1. markdown 参考链接写法

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"

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

Image — 图片

行内形式

![alt text](/path/to/img.jpg "Title")
//title非必填项

参考形式

![alt text][id]

[id]: /path/to/img.jpg "Title"

以上两种形式的HTML输出代码均为:

<img src="/path/to/img.jpg" alt="alt text" title="Title" />

插入HTML标签

在一般的段落文字中,可以使用反引号 ` 来标记代码区段,区段内的 &、\< 和 > 都会被自动的转换成 HTML 实体,这项特性让你可以很容易的在代码区段内插入 HTML 码:

I strongly recommend against using any <blink> tags.

I wish SmartyPants used named entities like &mdash;
instead of decimal-encoded entites like &#8212;.

自定义表格

1.语法说明

  • 第一行为表头,第二行分隔表头和主体部分,第三行开始每一行代表一个表格行;
  • 列与列之间用管道符号 “|” 隔开,原生方式的表格每一行的两边也要有管道符;
  • 可在第二行指定不同列单元格内容的对齐方式,默认为左对齐,在 “-” 右边加上 “:” 为右对齐,在 “-” 两侧同时加上 “:” 为居中对齐。

2.markdown写法

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |

3.输出展示

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

Markdown编辑器

Mou


由于Mou暂时不支持10.12.2 Sierra版本,于是放弃了。

Macdown



说起来 Macdown 和 Mou 还是有一段鲜为人知的虐恋史的,有兴趣可以baidu一下。
Macdown的操作界面分为左右两部分,分别是markdown和渲染后的预览,实时更新,体验非常友好。

Ulysses


功能很强大,不过由于Macdown就已经能满足我平时写写blog的需求,就没做太多研究。

Markdown Pad



上面的几款说的都是MAC OS下的,windows下免费又不捆绑广告和产品的编辑器,口碑最好的必须是Markdown Pad了,界面友好,操作简单,非常能满足写写blog的需求了。