[UT]Markdown语法(github版)

  • Post author:
  • Post category:其他


[TOC]

原文翻译自github的

Basic writing and formatting syntax



Working with advanced formatting

.

why using markdown?(为什么使用Markdown)

Markdown是一种易于读写的文本标记。

可以方便你做好学习笔记等工作,比简单的记事本码字来说相对的对于格式比较容易控制。

可以很容易的写出格式整齐美观,易于阅读的笔记,而且可以通过Markdown Preview生成网页排版的笔记标注等。

易于学习,即使一段时间不用,也只要几分钟回顾之前的书写文本学习,一次学会终生受益。

这里使用了Sublime Text作为编辑器,请自行寻找如何在Sublime上安装Markdown扩展。

基本书写格式规范

Headings(标题)

要创建一个Heading,只要在文字前加入1~6个

#

符号,来决定标题的大小。即HTML中的H1~H6。

# the largest heading
## the second largest heading
###### the smallest heading

效果如下:

the largest heading

the second largest heading

the smallest heading

Styling text(文本样式)

可以使用如下表几个标记来表示文本段的格式,如加重,斜体,划线等

样式 语法 例子 输出
加重(bold)
** **

or

__ __

**this is bold text**

this is bold text
斜体(italic)
* *

or

_ _

*this text is italicized*

this text is italicized
划线(strikethrough)
~~ ~~



this text was mistaken

this text was mistaken
加重斜体混合使用
** **

and

_ _

**This text is _extreamely_ important**

This text is

extreamely

important

Quoting text(引用)

使用

>

符号来说明该段文本为引用

鲁迅曾经说过:
> 苟利国家生死以,????

效果如下:

鲁迅曾经说过:

苟利国家生死以,????

Quoting code(代码引用)

代码引用有两种方式以` `和“` “`

使用`git status`来列出所有新修改未提交的文件。

效果如下:

使用

git status

来列出所有新修改未提交的文件。

Links(链接)

使用

[ ]

来创建一个内联链接,然后将链接的URL写进

( )

[百度首页](https://www.baidu.com/)

效果如下:


百度首页

相对链接

上个例子使用了绝对链接,当然也可以直接使用相对链接

[xxxxx](docs/xxxxx.md)

效果如下:


xxxxx

Lists(列表)

在一行或者多行前加上

-

或者

*

,效果类似于HTML中的

ul

无序列表

- George Washington
- John Adams
- Thomas Jefferson

效果如下:

  • George Washington
  • John Adams
  • Thomas Jefferson

还可以插入有序列表

ol

,语法是使用数字标记每行之前

1. James Madison
2. James Monroe
3. John Quincy Adams

效果如下:

1. James Madison

2. James Monroe

3. John Quincy Adams

列表内也可以嵌套列表比如:

8. Make my changes
    1. Fix bug
    2. Improve formatting
        * Make the headings bigger
2. Push my commits to GitHub
3. Open a pull request
    * Describe my changes
    * Mention all the members of my team
        * Ask for feedback

效果如下:

  1. Make my changes

    1. Fix bug
    2. Improve formatting

      • Make the headings bigger
  2. Push my commits to GitHub
  3. Open a pull request

    • Describe my changes
    • Mention all the members of my team

      • Ask for feedback

注意到上面第一点虽然写的是8但是在实际效果中仍然正确显示1.这是正常的。

Task lists(任务列表)

在列表条目前使用

[ ]

来标记,如果该条目完成则使用

[x]

标记。

- [x] Finish my changes
- [ ] Push my commits to GitHub
- [ ] Open a pull request

效果如下:

  • [x] Finish my changes
  • [ ] Push my commits to GitHub
  • [ ] Open a pull request

    这里需要注意的事,若是写成了链接的形式,则需要对歧义部分的歧义字符进行转义。

- [ ] \(Optional) Open a followup issue

效果如下:

  • [ ] (Optional) Open a followup issue

Using emoji(使用emoji表情)

只要将emoji编码写入

:EMOJICODE:

中即可

@octocat :+1: This PR looks great - it's ready to merge! :shipit:

效果如下:

@octocat :+1: This PR looks great – it’s ready to merge! :shipit:

Ignoring Markdown formatting(转义字符)

若是文本中出现了可能会带来Markdown解析器解析歧义的字符,可以使用转义符转义字符

Let's rename \*our-new-project\* to \*our-old-project\*.

效果如下:

Let’s rename *our-new-project* to *our-old-project*.

Markdown语法进阶

创建表格

创建表格需要用到

|



-



-

来表示表头,而

|

则是用来分隔表中行中的条目。

| First Header  | Second Header |
| ------------- | ------------- |
| Content Cell  | Content Cell  |
| Content Cell  | Content Cell  |

效果如下:

First Header Second Header
Content Cell Content Cell
Content Cell Content Cell

表格单元随着条目长度自动调整,无需特别在意。至少需要使用3个

-

来表示表头。

| Command | Description |
| --- | --- |
| git status | List all new or modified files |
| git diff | Show file differences that haven't been staged |

效果如下:

Command Description
git status List all new or modified files
git diff Show file differences that haven’t been staged

Formatting content with your table(格式表格内内容排版)

表格内容可以居左,居中,居右布局,只需要使用

:

来表示布局的方式

| Left-aligned | Center-aligned | Right-aligned |
| :---         |     :---:      |          ---: |
| git status   | git status     | git status    |
| git diff     | git diff       | git diff      |

效果如下:

Left-aligned Center-aligned Right-aligned
git status git status git status
git diff git diff git diff

总结

最后的最后,如果你的某些格式不能起作用,请在md语法前换行,或者是语法后空格。

如果在CSDN中,自动生成目录则是使用

[TOC]

来自动根据

h1~h6

标签生成的。

github的Markdown语法同时也推荐了Daring Fireball的

Markdown Syntax


本文也是使用了Markdown所写,部分专门对于github才有效的语法并未写入。