Markdown语法详解

简介

Markdown有两层意思:一是轻量级、纯文本语法格式的标记语言;二是编辑并解析markdown语法,展示最终文字排版效果的客户端。markdown使得文字排版标准化,可以轻松转换成HTML或其他格式。让你专注于文字内容,而无需浪费时间在文字排版上。


标题

语法:#

  • markdown写法:

    # Heading level 1
    ## Heading level 2
    ### Heading level 3
    #### Heading level 4
    ##### Heading level 5
    ###### Heading level 6
    

段落

语法:空行分割,形成段落

  • markdown写法:

    段落1。
    
    段落2。
    
  • 实际效果:

    段落1。

    段落2。


换行

语法:正常段落换行用 2空格+回车;表格中换行用<br>

  • markdown写法:

    This is the first line.  
    And this is the second line.
    
    This is the first line.<br>
    And this is the second line.
    
  • 实际效果:
    This is the first line.
    And this is the second line.

    This is the first line.
    And this is the second line.


斜体

语法:用*或者_包含斜体内容

  • markdown写法:

    Italicized text is the *cat's meow*.  
    Italicized text is the _cat's meow_.
    
  • 实际效果:

    Italicized text is the cat’s meow.

    Italicized text is the cat’s meow.


粗体

**或者__包含加粗内容;

  • markdown写法:

    I just love **bold text**.
    I just love __bold text__.
    
  • 实际效果:

    I just love bold text.

    I just love bold text.


粗体+斜体

***___包含内容

  • markdown写法:

    This text is ***really important***.
    This text is ___really important___.
    This text is __*really important*__.
    This text is **_really important_**.
    
  • 实际效果:
    This text is really important.
    This text is really important.
    This text is really important.
    This text is really important.


段落引用
  1. 段落开始处加上>

    • Markdown写法
      > Dorothy followed her through many of the beautiful rooms in her castle.

    • 实际效果:

      Dorothy followed her through many of the beautiful rooms in her castle.

  2. 多个段落引用

    • Markdown写法

      > Dorothy followed her through many of the beautiful rooms in her castle.  
      >
      > The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
      
    • 实际效果:

      Dorothy followed her through many of the beautiful rooms in her castle.

      The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

  3. 段落嵌套引用

    • Markdown写法

      > Dorothy followed her through many of the beautiful rooms in her castle.
      >
      >> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
      
    • 实际效果:

      Dorothy followed her through many of the beautiful rooms in her castle.

      The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

  4. 引用与其他元素配合使用

    • Markdown写法

      > **The quarterly results look great!**
      >
      > - Revenue was off the chart.
      > - Profits were higher than ever.
      >
      >  *Everything* is going according to **plan**.
      
    • 实际效果:

      The quarterly results look great!

      • Revenue was off the chart.
      • Profits were higher than ever.

      Everything is going according to plan.


列表
  1. 有序列表

    • Markdown写法

      1. First item
      2. Second item
      3. Third item
      4. Fourth item
      
    • ***实际效果:***(因为缩进下面本应该显示1,2,3这样的序列)

      1. First item
      2. Second item
      3. Third item
      4. Fourth item
  2. 无序列表(-+*用这三种符号实现)

    • Markdown写法(下面只用-说明)

      - First item
      - Second item
      - Third item
          - Indented item
          - Indented item
      - Fourth item
      
    • 实际效果:

      • First item
      • Second item
      • Third item
        • Indented item
        • Indented item
      • Fourth item
  3. 列表中插入段落

    • Markdown写法
      *   This is the first list item.
      *   Here's the second list item.
      
          I need to add another paragraph below the second list item.
      
      *   And here's the third list item.
      
    • 实际效果:
      • This is the first list item.

      • Here’s the second list item.
        I need to add another paragraph below the second list item.

      • And here’s the third list item.

  4. 列表中插入块引用

    • Markdown写法
      *   This is the first list item.
      *   Here's the second list item.
      
          > I need to add another paragraph below the second list item.
      
      *   And here's the third list item.
      
    • 实际效果:
      • This is the first list item.

      • Here’s the second list item.

        I need to add another paragraph below the second list item.

      • And here’s the third list item.


代码块
  1. 用 `包括一个词或短语

    • Markdown写法

      At the command prompt, type `nano`.
      
    • 实际效果:

      At the command prompt, type nano.

  2. 用 ```包含代码块

    • Markdown写法

        ```
        <head>
            <title>Test</title>
        </head>
        ```
      
    • 实际效果:

      <head>
        <title>Test</title>
      </head>
      

分割线

语法:***---___

  • Markdown写法

    ***
    ---
    ___
    
  • 实际效果:



链接
  1. 格式:[链接名](URL)

    • Markdown写法

      My favorite search engine is [Duck Duck Go](https://duckduckgo.com).
      
    • 实际效果:

      My favorite search engine is Duck Duck Go.

  2. 格式:[链接名](URL "Title") 增加链接Title(鼠标悬浮时显示)

    • Markdown写法

      My favorite search engine is [Duck Duck Go](https://duckduckgo.com "The best search engine for privacy").
      
    • 实际效果:

      My favorite search engine is Duck Duck Go.

  3. 链接配合其他元素使用

    • Markdown写法

      I love supporting **[EFF](https://eff.org)**.
      This is the *[Markdown Guide](https://www.markdownguide.org)*.
      
    • 实际效果:

      I love supporting EFF.

      This is the Markdown Guide.

  4. 链接嵌套

  5. 原文加链接优化

    • Markdown写法

      In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends
      of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
      eat: it was a [hobbit-hole](https://en.wikipedia.org/wiki/Hobbit#Lifestyle "Hobbit lifestyles"), and that means comfort.
      
      上面的写法和下面的写法,展示效果是一样的,但是上面把链接插入在原文中很不好阅读,可以用下面方式,方便修改阅读:
      
      In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends
      of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
      eat: it was a [hobbit-hole][1], and that means comfort.  
      
      [1]: <https://en.wikipedia.org/wiki/Hobbit#Lifestyle> "Hobbit lifestyles"
      
    • 实际效果:

      In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends
      of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
      eat: it was a hobbit-hole, and that means comfort.


URL变链接

语法:<URL>


图片

语法:![图片名](URL)

  • Markdown写法

    1.  Open the file containing the Linux mascot.
    2.  Marvel at its beauty.
    
    ![Tux, the Linux mascot](https://i-blog.csdnimg.cn/blog_migrate/1d0c4a9b57d5fa34918e4c4f5ea4500d.png)
    
    3.  Close the file.
    
  • 实际效果:

    1. Open the file containing the Linux mascot.
    2. Marvel at its beauty.

    百度

    1. Close the file.

特殊字符反引用

语法:\用反斜杠可以反引用下面特殊字符

  • Markdown写法

    * Without the backslash, this would be a bullet in an unordered list.
    \* Without the backslash, this would be a bullet in an unordered list.
    
  • 实际效果:

    • Without the backslash, this would be a bullet in an unordered list.

      * Without the backslash, this would be a bullet in an unordered list.

  • 可以处理的特殊字符

    \`*-{}[]()#+-·! 
    

兼容 HTML

Markdown中可以直接插入HTML,解析库默认是不开放的,需要参考对应库文档,markdown-it设置html: true

1、 Markdown 文件里加上 HTML 表格:
  • markdown写法:

    这是一个普通段落。
    <table>
    <tr>
        <td>Foo</td>
    </tr>
    </table>
    这是另一个普通段落。
    
  • 实际效果

    这是一个普通段落。

    Foo
    这是另一个普通段落。

2、Markdown嵌入视频
  • markdown写法:

    1. 插入视频
    <video src="视频链接" width="320" height="180" controls="controls"></video> 
    
  • 实际效果:


表格

语法:使用 | 来分隔不同的单元格,使用 - 来分隔表头和其他行。

  • markdown写法:

    | 左对齐 | 右对齐 | 居中对齐 |
    | :-----| ----: | :----: |
    | 单元格 | 单元格 | 单元格 |
    | 单元格 | 单元格 | 单元格 |
      
    -: 设置内容和标题栏居右对齐。
    :- 设置内容和标题栏居左对齐。
    :-: 设置内容和标题栏居中对齐。
    
  • 实际效果:

    左对齐右对齐居中对齐
    单元格单元格单元格
    单元格单元格单元格

其他参考链接
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值