GitHub Flavored Markdown (GFM) 语法总览。
虽然 Markdown 的核心语法元素是有限的,但通过组合、嵌套和特定于 GitHub 的扩展功能,可以实现非常丰富的效果。


一、 基本文本格式 (1-15)

  1. 标题 H1 (Setext-style): This is an H1 + =======

    This is an H1

  2. 标题 H2 (Setext-style): This is an H2 + -------

    This is an H2

  3. 标题 H1 (ATX-style): # H1

    H1

  4. 标题 H2 (ATX-style): ## H2

    H2

  5. 标题 H3 (ATX-style): ### H3

    H3

  6. 标题 H4 (ATX-style): #### H4

    H4

  7. 标题 H5 (ATX-style): ##### H5

    H5
  8. 标题 H6 (ATX-style): ###### H6

    H6
  9. 粗体 (Asterisks): **bold text**

    bold text

  10. 粗体 (Underscores): __bold text__

    bold text

  11. 斜体 (Asterisk): *italicized text*

    italicized text

  12. 斜体 (Underscore): _italicized text_

    italicized text

  13. 粗斜体 (Asterisks): ***bold and italic***

    bold and italic

  14. 粗斜体 (Underscores): ___bold and italic___

    bold and italic

  15. 删除线 (GFM): ~~The world is flat.~~

    The world is flat.

二、 列表 (16-30)

  1. 无序列表 - 星号: * Item

    • Item 1
    • Item 2
  2. 无序列表 - 加号: + Item

    • Item 1
    • Item 2
  3. 无序列表 - 连字符: - Item

    • Item 1
    • Item 2
  4. 有序列表: 1. First item

    1. First item
    2. Second item
  5. 嵌套列表 (无序内有序): * Item + 1. Nested ordered

    • Item
      1. Nested ordered
      2. Another nested
  6. 嵌套列表 (有序内无序): 1. First + * Nested unordered

    1. First
      • Nested unordered
      • Another nested
  7. 任务列表 (GFM): - [x] Completed task

    • Completed task
    • Incomplete task
  8. 列表项内的段落: * First line + + Paragraph break

    • This is the first line.

      And this is a paragraph within the list item.

  9. 列表项内的代码块: * Code: + + ` ```code````

    • Here is some code:

      function hello() { console.log("hi"); }
      
  10. 列表项内的引用: * Quote: + + > quote

    • A quote here:

      This is a quote inside a list.

  11. 不同层级缩进的列表 (Level 2): * Level 1 + + Level 2

    • Level 1
      • Level 2
        • Level 3
  12. 不同标记混用的列表 (Level 2): 1. Ordered + * Unordered nested

    1. Ordered
      • Unordered nested
    2. Next ordered
  13. 紧凑列表 (无空行): * Item 1 + * Item 2

    • Item 1
    • Item 2
  14. 列表项内多个段落 (再次强调): * Para 1 + + Para 2

    • This is the first paragraph in the list item.

      This is the second paragraph in the same list item.

  15. 列表中的复杂结构 (综合): 在列表项中混合使用代码、引用等。

    • Complex Item:
      1. Step one.
        console.log('code');
      2. Step two.

        A nested quote.

三、 链接与图片 (31-45)

  1. 内联链接: [title](https://example.com)

    My Website

  2. 带标题的内联链接: [title](https://example.com "Optional title")

    My Website

  3. 自动链接 (URL): <https://www.example.com>

    https://www.example.com

  4. 参考式链接 (定义): [Reference link][id] + [id]: https://example.com

    Reference link

  5. 图片 (内联): ![alt text](/path/to/img.jpg)

    An image

  6. 带链接的图片: [![alt text](/path/to/img.jpg)](https://example.com)

    An image

  7. 图片 (参考式): ![alt text][img-id] + [img-id]: /path/to/img.jpg

    An image

  8. 为图片添加链接 (方法二): 使用HTML <a> 标签。

    <a href="https://example.com"><img src="https://placehold.co/150" alt="An image" /></a>

  9. 调整图片大小 (HTML): <img src="..." width="200" height="100">

    <img src="https://placehold.co/150" width="100" />

  10. 居中图片 (HTML/CSS): <p align="center">...<img>...</p>

    <p align="center"><img src="https://placehold.co/150" /></p>

  11. 链接到锚点: [Go to Section](#section-title)

    (需要页面内有对应的 ## Section Title )

  12. 链接到仓库文件: [Link to file](./path/to/file.md)

    Link to README

  13. 链接到 Issues/Pull Requests: #123

    See issue #123 for more details.

  14. 链接到特定用户: @username

    Thanks for your contribution, @octocat!

  15. 链接到特定提交 (Commit): 00213a8bd...

    The fix was introduced in 00213a8bd...

四、 引用与水平线 (46-55)

  1. 基本引用: > blockquote

    This is a blockquote.

  2. 嵌套引用: > Outer + >> Inner

    This is the outer quote.

    This is the inner quote.

  3. 引用内含列表: > * List in quote

    • A list item in a blockquote
    • Another item
  4. 引用内含代码: > code``

    Inline code inside a blockquote.

  5. 引用内含标题: > # Title in quote

    A heading in a blockquote

  6. 引用后紧跟段落: 正确的格式需要用两个空格换行或空行分隔。

    This is a quote.

    This is a new paragraph.

  7. 多段落引用 (Paragraph breaks): > Para 1 + > + > Para 2

    This is the first paragraph of the blockquote.

    This is the second paragraph.

  8. 水平线 (连字符): ---


  9. 水平线 (星号): ***


  10. 水平线 (下划线): ___


五、 代码 (56-70)

  1. 行内代码: `code`

    Here is some inline code.

  2. 代码块 (围栏式, 无语言):

    ...
    code here
    ...
    Sample text here...
    
  3. 代码块 (围栏式, 指定语言):

    ...python
    def hello():
        print("Hello")
    ...
    def hello():
        print("Hello")
  4. 代码块 (缩进式): Indent every line with 4 spaces.

    function hello() {
        console.log("Hello");
    }
    
  5. 包含反引号的行内代码: ```` `code` ``

    This is `backticks` inside inline code.

  6. 代码块中的缩进: 保持代码原有的缩进。

    {
      "key": "value"
    }
  7. 代码块中的特殊字符: 代码块会原样显示,无需转义。

    <div class="test"> &lt; &gt; </div>
  8. 行内高亮 (非标准): GitHub 不直接支持,但可用HTML <mark>

    Use <mark>highlighted</mark> text.

  9. 长代码块 (滚动): 长代码会自动出现横向滚动条。

    This is a very long line of text that will demonstrate the horizontal scrolling behavior of a code block in GitHub Flavored Markdown. It should allow users to scroll horizontally to see all the content without breaking the layout.
    
  10. 代码块内换行: 在代码语言标识符后加 {1,2} 可指定高亮行(此为YAML Front Matter风格,非GFM标准,但某些渲染器支持)。

    (此功能非GFM标准,不保证通用性)

  11. 注释 (HTML): <!-- This is a comment -->

  12. 转义字符 (Backslash): \*literal asterisks\*

    *literal asterisks*

  13. 转义反引号: ```literal backtick``

    \literal backtick`(显示为 ` ``)

  14. 转义井号: \# Not a header

    # Not a header

  15. 转义感叹号: \! Not an image

    ! Not an image

六、 表格 (GFM 扩展, 71-80)

  1. 基本表格:

    | Syntax      | Description |
    | ----------- | ----------- |
    | Header      | Title       |
    | Paragraph   | Text        |
    Syntax Description
    Header Title
    Paragraph Text
  2. 左对齐 (默认): | :--- |

    Left-aligned
    Content
  3. 右对齐: | ---: |

    Right-aligned
    Content
  4. 居中对齐: | :---: |

    Center-aligned
    Content
  5. 混合对齐:

    Left Center Right
    A B C
  6. 表格内使用行内格式: | *Italic* | **Bold** |

    Italic Bold Code
    Cell 1 Cell 2 Cell 3
  7. 空单元格表格:

    Col 1 Col 2
    Data
    Data
  8. 长文本换行:

    Short Long Text Column
    A This is a very long piece of text that will wrap within the table cell to demonstrate how content flows.
  9. 表格内代码:

    Command Description
    git status List all new or modified files
  10. 表格作为布局工具 (不推荐): 不应滥用表格做文档布局。

七、 其他 GFM 特有功能 (81-100)

  1. 提及用户 (@): @github

    Please review this PR, @Reviewer.

  2. 引用 Issue 或 Pull Request (#): #1

    Fixes #1

  3. 引用特定提交 (SHA): 6a5b3f1

    The bug was fixed in 6a5b3f1.

  4. 表情符号 (Emoji) (使用别名): :smile:

    This is great! 😄

  5. 表情符号 (使用 Unicode): 😀

    Look, a smiley face! 😀

  6. Strikethrough in Tables:

    Feature Status
    Old feature Deprecated
  7. Task Lists in Comments:

    • Understand task lists
    • Close the issue
  8. Shorthand for Web URLs: 自动识别 https://example.com

    Visit https://example.com for more info.

  9. Highlighting (Fenced Code Blocks): 见第58条,语法高亮是其重要功能。

  10. Diff Formatting in Code Blocks:

    + Added line
    - Removed line
    + Added line
    - Removed line
  11. 折叠细节 (HTML Details/Summary):

  12. Mermaid 图表 (在支持的环境中):

    graph TD;
        A-->B;
        A-->C;
  13. 警告提示框 (HTML Block):

  14. 行内 HTML: <strong>HTML bold</strong>

    Use if needed.

  15. HTML 换行: <br>

    First LineSecond Line

  16. HTML 分区: <div>...</div>

    <div align="right">Right-aligned content.</div>

  17. 脚注 (非标准GFM, 部分平台支持): [^1]

    This is a sentence with a footnote.1

  18. 定义列表 (非标准GFM): 通常需用HTML <dl>, <dt>, <dd>

  19. 数学公式 (LaTeX, 非标准GFM): $\sqrt{3}$,GitHub本身不直接渲染,但可在支持的编辑器或CI/CD流程中处理。

  20. YAML Front Matter: (用于 Jekyll 等静态博客)

    ---
    title: My Page
    ---

    (放置在Markdown文件最顶部)


Footnotes

  1. This is the footnote definition.

🤞转载请注明出处🤞