目录
前言
本文根据markdown官方文档总结出小白使用Markdown的无脑 正确姿势。
标题#
标题前添加“#
”(数量1-6)
# This is an H1
## This is an H2
另一种写法:在文本下一行添加 “ =
”和“ -
”组成的 “分割线 ”(====================
(用于第一级标头)或者---------------------
(用于第二级标头))。例如:
A First Level Header
====================
A Second Level Header
--------------------
两种写法输出效果是一样的:
A First Level Header
A Second Level Header
A Second Level Header
引用>
在引用的文字前添加“>”。
> This is a blockquote.
> This is the second paragraph in the blockquote.
> ## This is an H2 in a blockquote
输出:
This is a blockquote.
This is the second paragraph in the blockquote.
This is an H2 in a blockquote
>>嵌套引用 添加标题列表代码块直接添加相关代码:
> ## This is a header.
>
>> 1. This is the first list item.
>> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
输出:
This is a header.
- This is the first list item.
- This is the second list item.
Here’s some example code:
return shell_exec(“echo $input | $markdown_script”);
清单
无序 (* + -)
* ,+ ,- 有一样的效果
* Candy.
* Gum.
* Booze.
这个:
+ Candy.
+ Gum.
+ Booze.
还有这个:
- Candy.
- Gum.
- Booze.
全部产生相同的输出:
- Candy.
- Gum.
- Booze.
有序(1.2.3.)
1. Bird
2. McHale
3. Parish
输出:
- Bird
- McHale
- Parish
高级(与html的关系)
如果列表项用空白行分隔,则Markdown会包装HTML输出中<p>
标记中的项目:
* Bird
* Magic
输出:
- Bird
- Magic
代码
代码块 ```
预格式化的代码块用于编写有关编程或标记源代码。这些行而不是形成普通的段落代码块中的一个按字面意义解释。Markdown包装了一个代码块在
<pre>
和<code>
标签中。要在Markdown中生成代码块,只需缩进代码行的每一行至少间隔4个空格或1个制表符。例如,给定此输入:
This is a normal paragraph: This is a code block.
输出:
This is a normal paragraph:
This is a code block.
扩展:HTML中
<p>This is a normal paragraph:</p> <pre><code>This is a code block. </code></pre>
从每个缩进一级缩进-4个空格或1个制表符代码块的行。
Here is an example of AppleScript: tell application "Foo" beep end tell
输出:
Here is an example of AppleScript:
tell application "Foo" = beep end tell
代码块将继续直到到达未缩进的行(或文章结尾)。
在代码块内,与号(
&
)和尖括号(<
和>
)会自动转换为HTML实体。这使得它非常使用Markdown轻松包含示例HTML源代码-只需粘贴并缩进它,Markdown将处理编码的麻烦和号和尖括号。<div class="footer"> © 2004 Foo Corporation </div>
输出:
扩展:HTML中
<pre><code><div class="footer"> &copy; 2004 Foo Corporation </div> </code></pre>
代码 ``
要指示代码范围,请使用反引号将其引起来(```’’)。与预先格式化的代码块不同,代码跨度指示正常段落。例如:
Use the `printf()` function.
输出
Use the
printf()
function.要在代码范围内包含文字反引号字符,可以使用多个反引号作为开始和结束定界符:
``There is a literal backtick (`) here.``
输出
There is a literal backtick (`) here.
代码范围周围的反引号分隔符可能包含空格-打开后一个,关闭前一个。这可以让您放置在代码范围的开头或结尾处的文字反引号字符:
A single backtick in a code span: `` ` `` A backtick-delimited string in a code span: `` `foo` ``
输出
A single backtick in a code span:
`
A backtick-delimited string in a code span:
`foo`
使用代码跨度时,“&”号和尖括号被编码为HTML实体自动生成,因此很容易包含示例HTML标签。Markdown会变成这样:
Please don't use any `<blink>` tags.
输出
Please don't use any
<blink>
tags.您可以这样写:
`—` is the decimal-encoded equivalent of `—`.
输出
—
is the decimal-encoded equivalent of—
.水平线 ***
<hr />
* * * *** ***** - - - ---------------------------------------
超链接
链接
Markdown支持两种链接样式:inline 和 reference。超链接在[方括号]中,地址在(小括号)内。请例如:
This is [an example](http://example.com/ "Title") inline link. [This link](http://example.net/) has no title attribute.
输出
This is an example inline link.
This link has no title attribute.
在HTML中的代码:
<p>This is <a href="http://example.com/" title="Title"> an example</a> inline link.</p> <p><a href="http://example.net/">This link</a> has no title attribute.</p>
如果要引用同一服务器上的本地资源,则可以使用相对路径:
See my [About](/about/) page for details.
输出
See my About page for details.
以下三个链接定义是等效的:
[foo]: http://example.com/ "Optional Title Here"
[foo]: http://example.com/ 'Optional Title Here'
[foo]: http://example.com/ (Optional Title Here)
Note: 链接URL可以可选地用尖括号括起来可以防止其他符号的影响:
[id]: <http://example.com/> "Optional Title Here"
强调** **
Markdown将星号()和下划线(__)视为重点。用或_换行的文本将用换行HTML
<em>
标签;双*
或_
将被HTML换行<strong>
标签。HTML:
<em>single asterisks</em> <em>single underscores</em> <strong>double asterisks</strong> <strong>double underscores</strong>
markdown中:
*single asterisks* _single underscores_ **double asterisks** __double underscores__
输出:
single asterisks
single underscores
double asterisks
double underscores
您可以使用任何喜欢的样式。唯一的限制是必须使用相同的字符来打开和关闭重点跨度。强调可以用在单词的中间:
un*frigging*believable
但是,如果您在
*
或_
周围加上空格,则将其视为文字星号或下划线。在其位置产生文字星号或下划线否则将用作强调定界符,您可以反斜杠逃脱它:\*this text is surrounded by literal asterisks\*
图片
类似链接,允许两种样式:* inline 和 reference *。
![Alt text](/path/to/img.jpg) ![Alt text](/path/to/img.jpg "Optional title")
引用样式的图像语法如下所示:
![Alt text][id]
其中“ id”是定义的图像引用的名称。图片参考使用与链接引用相同的语法定义:
[id]: url/to/image "Optional title attribute"
如果要更改图片大小,需要使用常规HTML
<img>
标签。其他
自动链接<>
用尖括号将URL或电子邮件地址括起来。
<http://example.com/>
如果是邮箱地址,Markdown会执行一些随机的十进制和十六进制实体编码,以掩盖你真实邮箱地址,防止地址收集机器人收集你的信息。
在Markdown中输入:<address@example.com>
输出:
而它的HTML是这样的:
<a href="mailto:addre ss@example.co m">address@exa mple.com</a>
自定义格式
markdown并没有直接的更改功能,需要结合HTML进行更改
表格与引用的背景色更改:<table><td bgcolor=yellow> 背景色 </td></table>
字体颜色大小
<font color=颜色 size=数字>
图片大小
<img src="图片名称" width="50%" height="50%">
图片居中
<div align=right><img src="图片名称" width="50%" height="50%"></div>
直接使用符号 \
\
可以跳过markdown语法直接使用符号:符号 英文 中文 \ backslash 反斜杠 ` backtick 反t * asterisk 星号 _ underscore 下划线 {} curly braces 大括号 [] square brackets 中括号 () parentheses 括弧 # hash mark 井号 + plus sign 加号 - minus sign (hyphen) 减号 . dot 点 ! exclamation mark 感叹号