Markdown Tutorial
Markdown 概述
简介
Markdown 是一种轻量级标记语言, 创始人为约翰·格鲁伯(英语: John Gruber). 它允许人们“使用易读易写的纯文本格式编写文档, 然后转换成有效的XHTML(或者 HTML)文档”. 这种语言吸收了很多在电子邮件中已有的纯文本标记的特性.
由于 Markdown 的轻量化, 易读易写特性, 并且对于图片, 图表, 数学式都有支持, 当前许多网站都广泛使用 Markdown 来撰写帮助文档或是用于论坛上发表消息. 例如: GitHub, reddit, Diaspora, Stack Exchange, OpenStreetMap, SourceForge 等. 甚至 Markdown 能被使用来撰写电子书.
优点
- 专注文字内容而不是排版样式, 降低写作成本, 提高写作效率.
- 轻松的导出 HTML, PDF 和本身的 .md 文件.
- 纯文本内容, 兼容所有的文本编辑器与字处理软件.
- 可读, 直观, 学习成本低.
- 随时修改文章版本, 不必像字处理软件生成若干文件版本导致混乱.
- 可以通过 Git 方便控制版本.
Markdown 资料
官方文档
创始人 John Gruber 的 Markdown 语法说明
中文技术文档的写作规范
当使用系统关键字时, 以关键字+空格
的形式, 不仅方便阅读, 也方便编辑.
Markdown 排版
标题
1 | # 一级标题 |
1 | 一级标题 |
列表
无序列表, 可以将内容缩进, 达成子列表效果.
1 | * 列表内容. |
HTML: 无序列表
1 | <ul> |
有序列表
1 | Num. 列表内容. |
HTML: 有序列表
1 | <ol> |
Task List
1 | - [ ] 未完成 |
Example
- 未完成
- 已完成
HTML
1 | <input type="checkbox"> 未完成 <br> |
Example
未完成
已完成
分割线
1 | --- |
链接, 图片, 和内部跳转
Hyperlink
1 | 通过在文字后直接插入url实现 |
1 | [文字内容][id] |
超链接(英语:Hyperlink)是指超文本内由一文件连接至另一文件的链接. 作用与论文中的参考或注释类似, 以方便读者随时参考某一词汇的定义.
图片
1 | 通过在图片名(可以为空)后插入url实现插入图片 |
1 | 通过在图片名(可以为空)后插入id, 再在id后插入url实现规范正文格式 |
Without Alt & Title
1 | ![](https://raw.githubusercontent.com/ZacksAmber/PicGo/master/img/Einstein.jpg) |
With Alt & Title
1 | ![Einstein](https://raw.githubusercontent.com/ZacksAmber/PicGo/master/img/Einstein.jpg "This is Einstein") |
调整图片大小
1 | <img src="https://raw.githubusercontent.com/ZacksAmber/PicGo/master/img/Einstein.jpg" width=210 height=100 /> |
根据比例调整图片大小
1 | <img src="https://raw.githubusercontent.com/ZacksAmber/PicGo/master/img/Einstein.jpg" width=210 height=100 /> |
调整图片位置
1 | {% img [class names] /path/to/image [width] [height] "title text 'alt text'" %} |
Einstein
1 | <img src="https://raw.githubusercontent.com/ZacksAmber/PicGo/master/img/Einstein.jpg" width="50%" height="50%" div align = "center" /> |
Group Pictures
https://theme-next.js.org/docs/tag-plugins/group-pictures.html
1 | {% gp 1-1 %} |
内部跳转(通过标题)
1 | 需要跳转的章节 |
1 | 需要插入内部链接的内容 |
MarkDown不支持自定义跳转, 因此通过html的形式实现
P.S: h2 是二级标题, 相当于 ##, 以此类推, h3 相当于 ###.
Example
点击此处跳转到下一章第一节“代码块”
1 | 点击此处跳转到下一章第一节["代码块"](#code-block) |
Markdown Content
Code Block
Code in Line
1 | This is a `code in line`. |
This is a code in line
.
Code block
```*Language*
This is code block
```
Example
1 | import numpy py |
1 | This is code block |
``` [language] [title] [url] [link text] code snippet ```
Title
```*Language* *Title*
Code
```
1 | for i in range (0, 3): |
Show line-number
```Language {.lines-number}
Code Block
```
1 | This is 1st line |
Highlight specific line (Do not work in Hexo)
```Language {highlight=[1-10,15,20-22]}
Code
```
1 | for i in range (0, 3): |
HTML
1 | <pre><code> |
Code Block
1 | <code>Code inline</code> |
Code inline
字体外观
1 | *斜体*, _斜体_ |
备注
Hexo plug: npm install markdown-it-footnote –save
脚注的注意事项
- 带id的脚注是和带id的reference共用id的, 因此不可设置成一样的id, 否则会冲突.
- 脚注无论放在哪, 在预览时都会固定跳转到页面底部.
Example of footnote
HK[^99]
[^99]: 光复香港, 时代革命.
缩略词
1 | *[缩略词]: 悬浮显示, 不可跳转, 无id. |
Example of abbreviation
The HTML specification is maintained by the W3C.
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
1 | The HTML specification is maintained by the W3C. |
引用
1 | > 引用内容 |
插入超链接引用, 见hyperlink 第二部分
转义
通常使用 \ 转义系统关键字, 还可以使用代码块来转义大段内容; 特殊情况下可以使用 Note 来转义内容.
1 | \系统关键字 |
1 | 需要转义的内容 |
1 | <html block> |
1 | {% note %} |
需要转义的内容
1 | \ |
Markdown 表格
表头和单元格
分隔符
- 分隔列:
|
- 分隔表头:
-
-
可以复数个.- 为了方便阅读,
|
和-
之间使用空格分开.
对齐
- 左对齐:
:-
,-
- 中间对齐:
:-:
- 右对齐:
-:
1 | |Left|Middle|Right| |
Left | Middle | Right |
---|---|---|
aaa | bbbb | cccc |
a | b | c |
HTML 表格
HTML 表格
P.S: 适用于Markdown表格无法转义的一些特殊字符, 比如|
也可以使用|
来代替|
, 以免出现bug
- 表格开头不能有 tab 或 space
- 每个表格由
table
标签开始 - 每个表格行由
tr
标签开始 - 每个表格数据由
td
标签开始 - 每个表头由
th
定义- 大多数浏览器会把表头显示为粗体居中的文本
- 使用
&nhsp
作为占位符可以显示空表格 - 使用
<div></div>
包含整个表格来定义全局- 使用
style="text-align:center"
, or left, or right 来定义表格全局排版
- 使用
1 | <div style='text-align:left'> |
Heading1 | Heading2 |
---|---|
row 1, cell 1 | row 1, cell 2 |
row 2, cell 1 | row 2, cell 2 |
Not null |
Markdown 数学
Web用户可能需要额外插件
LATEX:玩转数学公式 by Leahlijuan
List of Greek letters and math symbols by Overleaf
Markdown 中 LaTeX 数学公式命令 by Kiven
1 | $Math$ |
$f(x) = sinx$
1 | $$Math Block$$ |
$$f(x) = sinx$$
HTML
Image
1 | {% fullimage /url [@lazy], [alt], [title], [size] %} |
Full Image
Full Image with alt & title
Full Image with 100% size
Full Image with 200px & without alt & title
论文
字体
样式
1 | <font face="黑体">我是黑体字</font> |
Example
我是黑体字
我是微软雅黑
我是华文彩云
颜色
1 | <font color=#0099ff size=7 face="黑体">color=#0099ff size=72 face="黑体"</font> |
Example
color=#0099ff size=72 face=”黑体”
color=#00ffff
color=gray
大小
大小范围1~7, 默认3
1 | size 3 |
Example
size 3
size 5
强制分页(仅在导出pdf时生效)
1 | <div style="page-break-after: always;"></div> |
NexT Plugins
Note: This chapter is only for Hexo NexT user.
Note
1 | # Note tag style values: |
Note Example
1 | {% note danger %}It's wrong to write this tag with 1 line if you don't want to see possible bugs.{% endnote %} |
Note Class
1 | [class] : default | primary | success | info | warning | danger. |
1 | {% note %} |
Default Header
Welcome to Hexo!
1 | {% note default %} |
Primary Header
Welcome to Hexo!
1 | {% note primary %} |
Info Header
Welcome to Hexo!
1 | {% note info %} |
Success Header
Welcome to Hexo!
1 | {% note success %} |
Warning Header
Welcome to Hexo!
1 | {% note warning %} |
Danger Header
Welcome to Hexo!
1 | {% note danger %} |
1 | {% note info no-icon %} |
1 | {% note success %} |
1 | {% note default %} |
Table in Note
1 | 2 |
---|---|
3 | 4 |
5 | 6 |
7 | 8 |
1 | #### Table in Note |
Tabs
Settings
1 | tabs: |
Usage
1 | {% tabs Unique name, [index] %} |
Tabs
1 | {% tabs First unique name %} |
This is Tab 1.
This is Tab 2.
This is Tab 3.
Selected Tabs
1 | {% tabs Second unique name, 3 %} |
This is Tab 1.
This is Tab 2.
This is Tab 3.
1 | {% tabs Third unique name, -1 %} |
Tabs with no tab selected
Tabs with no tab selected
Tabs with no tab selected
Tabs with custom labels
1 | {% tabs Fourth unique name %} |
This is Tab 1.
This is Tab 2.
This is Tab 3.
Tabs with icons
1 | {% tabs Fifth unique name %} |
Tabs with icons only
This is Tab 1.
This is Tab 2.
This is Tab 3.
1 | Tabs with icons and labels |
Tabs with icons and labels
This is Tab 1.
This is Tab 2.
This is Tab 3.
Tabs permalinks test
1 | Permalink for > [Tab one](#tab-one). |
Tabs permalinks test
Permalink for > Tab one.
Permalink for > Tab one 1.
Permalink for > Tab one 2.
Permalink for > Tab one 3.
Permalink for > Tab two.
Permalink for > Tab two 1.
Permalink for > Tab two 2.
Permalink for > Tab two 3.
This is Tab 1.
This is Tab 2.
This is Tab 3.
This is Tab 1.
This is Tab 2.
This is Tab 3.
Tabs with other tags
1 | {% tabs Tags %} |
Tabs with other tags
This is Tab 1.
- One
- Two
- Three
4-spaces code block:
nano /etc
Tagged code block:
1 | code tag |
Note default tag.
This is Tab 2.
- Five
- Six
- Seven
This is Tab 3.
This is Sub Tab 1.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti. Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.
Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.
This is Sub Tab 2.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti. Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.
Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.
This is Sub Tab 3.
This is Sub-Sub Tab 1 of Sub Tab 3.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti. Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.
Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.
This is Sub-Sub Tab 2 of Sub Tab 3.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti. Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.
Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.
This is Sub-Sub Tab 3 of Sub Tab 3.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti. Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.
Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis. Vestibulum volutpat, lacus a ultrices sagittis, mi neque euismod dui, eu pulvinar nunc sapien ornare nisl. Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.
Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.
Settings
1 | pdf: |
Usages
1 | pdf: |
Mermaid
Settings
1 | # Mermaid tag |
Usage
1 | {% mermaid type %} |
graph graph TD A[Hard] -->|Text| B(Round) B --> C{Decision} C -->|One| D[Result 1] C -->|Two| E[Result 2]
Button
1 | {% button url, text, icon [class], [title] %} |
Label (高亮)
1 | Using <mark>Text</mark> as default markdown label. |
1 | <mark>This is important content needed to be heighlight</mark> |
This is important content needed to be heighlight
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Video
1 | {% video url %} |
1 | {% youtube 9f6MdHPG_64 %} |