你好,游客 登录 注册

[译] GitHub 风格的 Markdown 语法

[日期:2017-11-20] 来源:Linux社区  作者:cssmagic [字体: ]

声明:原文版权属于 GitHub。中文翻译部分并非官方文档,仅供参考。

GitHub uses "GitHub Flavored Markdown," or GFM, across the site--in issues, comments, and pull requests. It differs from standard Markdown (SM) in a few significant ways, and adds some additional functionality.

GitHub 全站支持 “GitHub 风格的 Markdown 语法”(简称 GFM),你可以用它来书写 issue、pull request(以下简称 “PR”)和各种评论。它和标准 Markdown 语法(SM)相比,存在一些值得注意的差异,并且增加了一些额外功能。

If you're not already familiar with Markdown, take a look at Markdown Basics. If you'd like to know more about features that are available in issues, comments, and pull request descriptions, such as task lists, read Writing on GitHub.

如果你对 Markdown 还不是很熟悉,可以先看一眼 Markdown 语法基础。如果你想了解在书写 issue、评论和 PR 描述时有哪些技巧(比如任务清单这样的高级功能),你应该读一下 GitHub 上的书写方式

Differences from traditional Markdown

与传统 Markdown 的差异

Multiple underscores in words


Where Markdown transforms underscores (_) into italics, GFM ignores underscores in words, like this:

Markdown 会把所有成对的下划线(_)转换为斜体,但 GFM 不会处理单词内的那些下划线,比如这些:

  • wow_great_stuff
  • do_this_and_do_that_and_another_thing.

This allows code and names with multiple underscores to render properly. To emphasize a portion of a word, use asterisks (*).


URL autolinking


GFM will autolink standard URLs, so if you want to link to a URL (instead of setting link text), you can simply enter the URL and it will be turned into a link to that URL.

GFM 会自动为标准的 URL 加上链接,因此,如果你只想链接到一个 URL(而不想设置链接文字),那你直接输入这个 URL 就可以了,它将被自动转换为一个链接。(译注:Email 地址也适用于此特性。)





GFM adds syntax to create strikethrough text, which is missing from standard Markdown.

GFM 增加了删除线语法,补上了标准 Markdown 在这方面的不足。

~~Mistaken text.~~



Mistaken text.

Fenced code blocks


Standard Markdown converts text with four spaces at the beginning of each line into a code block; GFM also supports fenced blocks. Just wrap your code in ````` (as shown below) and you won't need to indent it by four spaces. Note that although fenced code blocks don't have to be preceded by a blank line—unlike indented code blocks—we recommend placing a blank line before them to make the raw Markdown easier to read.

标准 Markdown 会把每行前面空四格的文本块转换为代码块;GFM 同时还支持围栏式代码块。只要把你的代码块包裹在 ````` 之间就行了(如下所示),你再也不需要通过无休止的缩进来标记代码块了。请注意,虽然围栏式代码块语法并不需要在头部插入空行(缩进式代码块语法是需要的),但我们仍然建议你留出空行,因为这样可以令 Markdown 源码的可读性更好。

Here's an example:

function test() {
  console.log("notice the blank line before this function?");

Keep in mind that, within lists, you must indent non-fenced code blocks eight spaces to render them properly.

请留意,列表中的代码块需要缩进 8 个空格,才会被正确地渲染。

Syntax highlighting


Code blocks can be taken a step further by adding syntax highlighting. In your fenced block, add an optional language identifier and we'll run it through syntax highlighting. For example, to syntax highlight Ruby code:

关于代码块的技巧还不止于此,你还可以为代码块指定语法着色效果。在围栏式代码块中,你可以指定一个可选的语言标识符,然后我们就可以为它启用语法着色了。比如说,这样可以为一段 Ruby 代码着色:

require 'redcarpet'
markdown ="Hello World!")
puts markdown.to_html

We use Linguist to perform language detection and syntax highlighting. You can find out which keywords are valid by perusing the languages YAML file.

我们使用 Linguist 来进行语言识别和语法着色。你可以在 语言 YAML 文件 中查证哪些语言标识符是有效的。



You can create tables by assembling a list of words and dividing them with hyphens - (for the first row), and then separating each column with a pipe |:


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

For aesthetic purposes, you can also add extra pipes on the ends:


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

Note that the dashes at the top don't need to match the length of the header text exactly:


| Name | Description          |
| ------------- | ----------- |
| Help      | Display the help window.|
| Close     | Closes a window     |

You can also include inline Markdown such as links, bold, italics, or strikethrough:

同时,你也可以在单元格内使用那些行内 Markdown 语法,比如加链接、加粗、加斜体或加删除线等等:

| Name | Description          |
| ------------- | ----------- |
| Help      | ~~Display the~~ help window.|
| Close     | _Closes_ a window     |

Finally, by including colons : within the header row, you can define text to be left-aligned, right-aligned, or center-aligned:


| Left-Aligned  | Center Aligned  | Right Aligned |
| :------------ |:---------------:| -----:|
| col 3 is      | some wordy text | $1600 |
| col 2 is      | centered        |   $12 |
| zebra stripes | are neat        |    $1 |

A colon on the left-most side indicates a left-aligned column; a colon on the right-most side indicates a right-aligned column; a colon on both sides indicates a center-aligned column.



You can use a subset of HTML within your READMEs, issues, and pull requests.

在 README、issue 和 PR 中,你还可以使用有限的一些 HTML 语法。

A full list of our supported tags and attributes can be found in the github/markup repository.

关于可用的标签和属性有哪些,你可以在 github/markup 这个项目中找到一份完整的清单。

Further reading



相关资讯       Markdown  Markdown语法 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数


  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款