markdown常用语法(个人觉得写博客足够用了)

兼容HTML语法

  Markdown是一种书写格式,它理念是,能让文档更容易读、写和随意改,
markdown兼容一些html的语法,所以你可以在markdown中直接书写一些html语法,但是
对于html的一些块元素(div, table, ul)来说,需要在这些块元素与普通的markdown之间插入空行,并且在
html代码中书写markdown的语法是无效的。对于HTML中的行内元素,(a, span, i)等,可以在markdown中直接使用,
根据个人习惯,例如你喜欢用html中的a标签表示链接,那么可以直接使用,而不需要使用markdown的链接语法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
* 这是markdown语法

<ol>
<li>foo</li>
<li>bar</li>
</ol>
<table>
<tr>
<td>hello</td>
<td>world</td>
</tr>
</table>

* 这是markdown语法
<a href="https://baidu.com/">百度一下</a>

markdown字符转换

  • 对于markdown文档中,你不需要像html那样考虑 *<* 和 & 这样的符号,这些符号markdown都会自动帮你转换,在markdown中,你写入实体也会帮你转
    换为正常的符号,例如:
    &copy; 会自动转换为 ©

markdown区块元素

换行

  • markdown的换行可以使用html, <br />元素换行,也可以使用markdown的语法,在需要换行的地方敲两个空格。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    * this is markdown grammer<br />
    or
    * this is markdown grammer
    ```
    ### 标题
    - markdown中的标题,类似于html中的 h1~h6, 但是markdown中可以使用,\=,和 \-, 以及 \#表示,
    \# 表示的时候有几个\# 就表示几级标题
    ```markdown
    # h1
    ## h2
    ### h3
    #### h4
    ##### h5
    ###### h6

区块引用blockquotes

  • markdown中建立区块引用使用 > 这个符号,只需要在段落的前面加一个就可以了:

    1
    > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
  • 对于整个段落,只需要加一个就可以了:

    1
    2
    > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
    id sem consectetuer libero luctus adipiscing.
  • 区块引用可以嵌套:

    1
    2
    3
    4
    > this is level of quoting
    >
    > > this is nested blockquote
    >
  • 区块内还可以包括标题,列表,代码块等语法

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    > ## 这是一个二级标题
    >
    > 1. 列表1
    > 2. 列表2
    >
    > 下面是代码片段:
    >
    > let a = '12'
    >
    > [hi](https://www.baidu.com)

markdown中的列表

  • markdown支持无序列表和有序列表
  • 无序列表使用,* 或者 - 或者 +
  • 有序列表使用,1. , 2. …
    1
    2
    * banana
    * apple
1
2
1. red
2. blue
  • 在列表中空行,会被添加p元素到每一项中:
    1
    2
    3
    * h1

    * h2

转换为html为:

1
2
3
4
<ul>
<li><p>h1</p></li>
<li><p>h2</p></li>
</ul>
  • 列表项目可以包含多个段落,每个项目下的段落都必须缩进 4 个空格或是 1 个制表符

    1
    2
    3
    4
    5
    6
    7
    *   This is a list item with two paragraphs.

    This is the second paragraph in the list item. You're
    only required to indent the first line. Lorem ipsum dolor
    sit amet, consectetuer adipiscing elit.

    * Another item in the same list.
  • 在列表中还可以书写区块引用

    1
    2
    3
    *   A list item with a blockquote:
    > this is a blockquote
    > this is a blockquote
  • 如果需要放入代码块,那么需要两个制表符:

    1
    2
    3
    * 一个列表:

    function(){}
  • 使用 \ 进行转义:

    1
    198\. greet

代码块

  • markdown中的代码块,可以使用缩进的方式表示,也可以使用 <!–14–>

分割线

  • 分割线可以使用三个 * 或者 三个 -, 建立:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    ***
    或者
    ---
    ```

    ## 区块元素
    ### 链接
    > 1. 外部链接
    > 2. 内部连接

    * 外部链接:
    ```markdown
    [百度一下](https://www.baidu.com/ "百度一下")

url地址后面的第二个参数是title,需要与前面url一个空格

  • 内部链接(锚链接)

    1
    2
    3
    <a href="#jump">页面内部跳转</a>
    在跳转的地方添加 id
    <a id="jump">页面跳转的位置</a>
  • 如果你是要链接到同样主机的资源,你可以使用相对路径:

    1
    See my [About](/about/) page for details.

强调

  • markdown强调使用,* 或者 _,* 一个,会被转换为 em标签包裹,** 会被转换为 strong标签包裹

    1
    2
    *em*
    **strong**
  • 局部代码标记

    1
    use this `console.log()` function

图片

  • markdown的图片表示如下:
    1
    2
    ![alt text](/path/to/img.jpg)
    ![alt text](/path/to/img.jpg "title")

反斜杠

  • 反斜杠可以用来转义,一些你需要在文本中展示的字符,不想要被编译出来
    1
    \*

总结

  • 以上就是我认为在markdown中常用的语法,其他的语法请参看我下面给出的相关链接,比如:markdown的表格,公式的编辑等等
  1. markdown语法简体中文版
  2. markdown中文官网
  3. 颜家大少的markdown网站
感谢您的阅读,本文由 Alex 版权所有。如若转载,请注明出处:Alex(https://sinianzhiren.github.io/2019/07/09/md-grammer/
安装hexo博客系统
vue 填坑知识(-)