GitHub Flavored Markdown (GFM) 语法总览。
虽然 Markdown 的核心语法元素是有限的,但通过组合、嵌套和特定于 GitHub 的扩展功能,可以实现非常丰富的效果。
一、 基本文本格式 (1-15)
-
标题 H1 (Setext-style):
This is an H1+=======This is an H1
-
标题 H2 (Setext-style):
This is an H2+-------This is an H2
-
标题 H1 (ATX-style):
# H1H1
-
标题 H2 (ATX-style):
## H2H2
-
标题 H3 (ATX-style):
### H3H3
-
标题 H4 (ATX-style):
#### H4H4
-
标题 H5 (ATX-style):
##### H5H5
-
标题 H6 (ATX-style):
###### H6H6
-
粗体 (Asterisks):
**bold text**bold text
-
粗体 (Underscores):
__bold text__bold text
-
斜体 (Asterisk):
*italicized text*italicized text
-
斜体 (Underscore):
_italicized text_italicized text
-
粗斜体 (Asterisks):
***bold and italic***bold and italic
-
粗斜体 (Underscores):
___bold and italic___bold and italic
-
删除线 (GFM):
~~The world is flat.~~The world is flat.
二、 列表 (16-30)
-
无序列表 - 星号:
* Item- Item 1
- Item 2
-
无序列表 - 加号:
+ Item- Item 1
- Item 2
-
无序列表 - 连字符:
- Item- Item 1
- Item 2
-
有序列表:
1. First item- First item
- Second item
-
嵌套列表 (无序内有序):
* Item+1. Nested ordered- Item
- Nested ordered
- Another nested
- Item
-
嵌套列表 (有序内无序):
1. First+* Nested unordered- First
- Nested unordered
- Another nested
- First
-
任务列表 (GFM):
- [x] Completed task- Completed task
- Incomplete task
-
列表项内的段落:
* First line++Paragraph break-
This is the first line.
And this is a paragraph within the list item.
-
-
列表项内的代码块:
* Code:++ ` ```code````-
Here is some code:
function hello() { console.log("hi"); }
-
-
列表项内的引用:
* Quote:++> quote-
A quote here:
This is a quote inside a list.
-
-
不同层级缩进的列表 (Level 2):
* Level 1++ Level 2- Level 1
- Level 2
- Level 3
- Level 2
- Level 1
-
不同标记混用的列表 (Level 2):
1. Ordered+* Unordered nested- Ordered
- Unordered nested
- Next ordered
- Ordered
-
紧凑列表 (无空行):
* Item 1+* Item 2- Item 1
- Item 2
-
列表项内多个段落 (再次强调):
* Para 1++Para 2-
This is the first paragraph in the list item.
This is the second paragraph in the same list item.
-
-
列表中的复杂结构 (综合): 在列表项中混合使用代码、引用等。
- Complex Item:
- Step one.
console.log('code');
- Step two.
A nested quote.
- Step one.
- Complex Item:
三、 链接与图片 (31-45)
-
内联链接:
[title](https://example.com) -
带标题的内联链接:
[title](https://example.com "Optional title") -
自动链接 (URL):
<https://www.example.com> -
参考式链接 (定义):
[Reference link][id]+[id]: https://example.com -
图片 (内联):
 -
带链接的图片:
[](https://example.com) -
图片 (参考式):
![alt text][img-id]+[img-id]: /path/to/img.jpg -
为图片添加链接 (方法二): 使用HTML
<a>标签。<a href="https://example.com"><img src="https://placehold.co/150" alt="An image" /></a> -
调整图片大小 (HTML):
<img src="..." width="200" height="100"><img src="https://placehold.co/150" width="100" /> -
居中图片 (HTML/CSS):
<p align="center">...<img>...</p><p align="center"><img src="https://placehold.co/150" /></p> -
链接到锚点:
[Go to Section](#section-title)(需要页面内有对应的
## Section Title) -
链接到仓库文件:
[Link to file](./path/to/file.md) -
链接到 Issues/Pull Requests:
#123See issue #123 for more details.
-
链接到特定用户:
@usernameThanks for your contribution, @octocat!
-
链接到特定提交 (Commit):
00213a8bd...The fix was introduced in 00213a8bd...
四、 引用与水平线 (46-55)
-
基本引用:
> blockquoteThis is a blockquote.
-
嵌套引用:
> Outer+>> InnerThis is the outer quote.
This is the inner quote.
-
引用内含列表:
> * List in quote- A list item in a blockquote
- Another item
-
引用内含代码:
>code``Inline
codeinside a blockquote. -
引用内含标题:
> # Title in quoteA heading in a blockquote
-
引用后紧跟段落: 正确的格式需要用两个空格换行或空行分隔。
This is a quote.
This is a new paragraph.
-
多段落引用 (Paragraph breaks):
> Para 1+>+> Para 2This is the first paragraph of the blockquote.
This is the second paragraph.
-
水平线 (连字符):
---
-
水平线 (星号):
***
-
水平线 (下划线):
___
五、 代码 (56-70)
-
行内代码:
`code`Here is some
inline code. -
代码块 (围栏式, 无语言):
... code here ...
Sample text here... -
代码块 (围栏式, 指定语言):
...python def hello(): print("Hello") ...def hello(): print("Hello")
-
代码块 (缩进式): Indent every line with 4 spaces.
function hello() { console.log("Hello"); } -
包含反引号的行内代码: ````
`code```This is
`backticks`inside inline code. -
代码块中的缩进: 保持代码原有的缩进。
{ "key": "value" } -
代码块中的特殊字符: 代码块会原样显示,无需转义。
<div class="test"> < > </div>
-
行内高亮 (非标准): GitHub 不直接支持,但可用HTML
<mark>。Use
<mark>highlighted</mark>text. -
长代码块 (滚动): 长代码会自动出现横向滚动条。
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. -
代码块内换行: 在代码语言标识符后加
{1,2}可指定高亮行(此为YAML Front Matter风格,非GFM标准,但某些渲染器支持)。(此功能非GFM标准,不保证通用性)
-
注释 (HTML):
<!-- This is a comment --> -
转义字符 (Backslash):
\*literal asterisks\**literal asterisks*
-
转义反引号: ```literal backtick``
\literal backtick`(显示为` ``) -
转义井号:
\# Not a header# Not a header
-
转义感叹号:
\! Not an image! Not an image
六、 表格 (GFM 扩展, 71-80)
-
基本表格:
| Syntax | Description | | ----------- | ----------- | | Header | Title | | Paragraph | Text |
Syntax Description Header Title Paragraph Text -
左对齐 (默认):
| :--- |Left-aligned Content -
右对齐:
| ---: |Right-aligned Content -
居中对齐:
| :---: |Center-aligned Content -
混合对齐:
Left Center Right A B C -
表格内使用行内格式:
| *Italic* | **Bold** |Italic Bold CodeCell 1 Cell 2 Cell 3 -
空单元格表格:
Col 1 Col 2 Data Data -
长文本换行:
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. -
表格内代码:
Command Description git statusList all new or modified files -
表格作为布局工具 (不推荐): 不应滥用表格做文档布局。
七、 其他 GFM 特有功能 (81-100)
-
提及用户 (@):
@githubPlease review this PR, @Reviewer.
-
引用 Issue 或 Pull Request (#):
#1Fixes #1
-
引用特定提交 (SHA):
6a5b3f1The bug was fixed in 6a5b3f1.
-
表情符号 (Emoji) (使用别名):
:smile:This is great! 😄
-
表情符号 (使用 Unicode):
😀Look, a smiley face! 😀
-
Strikethrough in Tables:
Feature Status Old feature Deprecated -
Task Lists in Comments:
- Understand task lists
- Close the issue
-
Shorthand for Web URLs: 自动识别
https://example.comVisit https://example.com for more info.
-
Highlighting (Fenced Code Blocks): 见第58条,语法高亮是其重要功能。
-
Diff Formatting in Code Blocks:
+ Added line - Removed line
+ Added line - Removed line
-
折叠细节 (HTML Details/Summary):
-
Mermaid 图表 (在支持的环境中):
graph TD; A-->B; A-->C;
-
警告提示框 (HTML Block):
-
行内 HTML:
<strong>HTML bold</strong>Use if needed.
-
HTML 换行:
<br>First LineSecond Line
-
HTML 分区:
<div>...</div><div align="right">Right-aligned content.</div> -
脚注 (非标准GFM, 部分平台支持):
[^1]This is a sentence with a footnote.1
-
定义列表 (非标准GFM): 通常需用HTML
<dl>,<dt>,<dd>。 -
数学公式 (LaTeX, 非标准GFM):
$\sqrt{3}$,GitHub本身不直接渲染,但可在支持的编辑器或CI/CD流程中处理。 -
YAML Front Matter: (用于 Jekyll 等静态博客)
--- title: My Page ---
(放置在Markdown文件最顶部)
Footnotes
-
This is the footnote definition. ↩