GitHub 风格的 Markdown 语法

GitHub 风格的 Markdown 语法

[译] GitHub 风格的 Markdown 语法

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

GitHub uses what we‘re calling "GitHub Flavored Markdown" (GFM) for messages, issues, and comments. It differs from standard Markdown (SM) in a few significant ways and adds some additional functionality.

GitHub 使用一种被称为“GitHub 风格的 Markdown 语法”(GFM)来书写版本注释、Issue 和评论。它和标准 Markdown 语法(SM)相比,存在一些值得注意的差异,并且增加了一些额外功能。

If you‘re not already familiar with Markdown, you should spend 15 minutes and go over the excellent Markdown Syntax Guide at Daring Fireball.

如果你对 Markdown 还不是很熟悉,那就应该花 15 分钟到 Daring Fireball 去复习一下这个精彩的 Markdown 语法指南。(译注:本文末尾提供了简体中文版的 Markdown 教程。)

If you prefer to learn by example, see the following source and result:

如果你更愿意通过案例来学习,则不妨看看下列源码和渲染结果的对照:

Tip: On Markdown-enabled portions of the site, press m on your keyboard to display a cheat sheet.

提示:在站内所有可用 Markdown 的场合,按 m 键可以显示快捷帮助。

Differences from traditional Markdown

与传统 Markdown 的差异

Newlines

换行

The biggest difference that GFM introduces is in the handling of linebreaks. With SM you can hard wrap paragraphs of text and they will be combined into a single paragraph. We find this to be the cause of a huge number of unintentional formatting errors. GFM treats newlines in paragraph-like content as real line breaks, which is probably what you intended.

GFM 引入的最大差异就是对换行的处理。在 SM 语法中,即使在一段文本中插入硬回车,这些文本仍然会被合并为一个段落。我们发现,这个特性导致了大量非预期的格式化错误。GFM 会把段落内容中的换行视为真正的换行,而这很可能正是你所期望的。

The next paragraph contains two phrases separated by a single newline character:

下面这个段落被一个换行符分隔成了两个短语:

Roses are red

Violets are blue

becomes

将被渲染为:

Roses are red
Violets are blue

Multiple underscores in words

单词中的多个下划线

It is not reasonable to italicize just part of a word, especially when you‘re dealing with code and names often appear with multiple underscores. Therefore, GFM ignores multiple underscores in words.

没有理由只把一个单词的 一部分 显示为斜体,尤其是当你在处理代码和那些经常出现多个下划线的名称时。因此,GFM 将忽略单词中的多个下划线。

perform_complicated_task

do_this_and_do_that_and_another_thing

becomes

将被渲染为:

perform_complicated_task
do_this_and_do_that_and_another_thing

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 地址也适用于此特性。)

Fenced code blocks

围栏式代码块

Markdown converts text with four spaces at the front of each line to code blocks. GFM supports that, but we also support fenced blocks. Just wrap your code blocks in ``` and you won‘t need to indent manually to trigger a code block.

Markdown 会把每行前面空四格的文本转换为代码块。GFM 也支持这种语法,同时,我们还支持围栏式代码块。只要把你的代码块包裹在 ``` 之间,你就不需要通过无休止的缩进来标记代码块了。

If you are indenting your code blocks with spaces, keep in mind that code within lists needs to be indented eight times in order to be properly marked as a code block.

如果你使用空格来缩进代码块,请留意列表中的代码块需要缩进 8 个空格,以确保它会被正确地标记为代码块。

Syntax highlighting

语法着色

We take code blocks a step further and add syntax highlighting if you request it. 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 代码着色:

```ruby

require ‘redcarpet‘

markdown = Redcarpet.new("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 文件 中查证哪些语言标识符是有效的。

Task Lists

任务清单

Further, lists can be turned into Task Lists by prefacing list items with [ ] or [x] (incomplete or complete, respectively).

不仅如此,列表还可以被转换为 任务清单,只需要为列表项的开头加上 [ ] 或 [x] 即可(分别表示未完成和已完成)。

- [x] @mentions, #refs, [links](), **formatting**, and <del>tags</del> supported

- [x] list syntax required (any unordered or ordered list supported)

- [x] this is a complete item

- [ ] this is an incomplete item

- [x] 支持 @提到某人、#引用、[链接]()、**格式化** 和 <del>标签</del> 等语法

- [x] 需要使用列表语法来激活(无序或有序列表均可)

- [x] 这是一个已完成项目

- [ ] 这是一个未完成项目

This feature is enabled for Issue and Pull Request descriptions, and comments. Task lists are also available in Gist comments, as well as Gist Markdown files. In those contexts, the task lists are rendered with checkboxes that you can check on and off.

这个特性会在 Issue 和 Pull Request 的描述和评论中启用。任务清单同样可用于 Gist 的评论和 Markdown 格式的 Gist。在这些场合,任务清单将渲染出复选框,供你勾选或清除。

See the Task Lists blog post for more details.

详情参见 关于任务清单的博文

Quick quoting

快速引用

Typing r on your keyboard lets you reply to the current issue or pull request with a comment. Any text you select within the discussion thread before pressing r will be added to your comment automatically and formatted as a blockquote.

按下键盘的 r 键将为当前的 Issue 或 Pull Request 添加评论。在按下 r 键之前,你在讨论区中选中的任何文本都将自动以一个块级引用的形式插入到你的评论中。(译注:这听起来只是一个便民功能,并不是语法上的差异。下面的一些功能也是这样。)

Name and Team @mentions autocomplete

@ 提到人名或团队名时的自动补全

Typing an @ symbol will bring up a list of people or teams on a project. The list will filter as you type, so once you find the name of the person or team you are looking for, you can use the arrow keys to select it and then hit enter or tab to complete the name. For teams, just enter the @organization/team-name and all members of that team will get subscribed to the issue.

按下 @ 符号将弹出一个列表,列出这个项目相关的人或团队。这个列表会随着你的输入不断匹配筛选,因此一旦你在列表中发现了你要找的人名或团队名,你就可以用方向键来选中它,然后按回车或 tab 键来补全。对于团队来说,只需要输入 @组织名/团队名,那么团队内的所有成员都将收到提醒。

The result set is restricted to repository collaborators and any other participants on the thread, so it‘s not a full global search. It uses the same fuzzy filter as the file finder and works for both usernames and full names.

列表的匹配范围仅限制在当前仓库的贡献者以及当前讨论的参与者,因此它并不是一个全局性的搜索。它和文件查找器使用相同的模糊筛选算法,并且同时适用于用户名和全名。

Check out the blog posts for more information about @mention autocompletes for users and teams.

详情参见关于 @ 提到 用户 和 团队 时自动补全的博文。

Emoji autocomplete

Emoji 表情符号的自动补全

Typing : will bring up a list of emoji suggestions. The list will filter as you type, so once you find the emoji you‘re looking for, just hit tab or enter to complete the highlighted result.

按下 : 将会弹出一个表情符号的建议列表。这个列表会随着你的输入不断匹配筛选,因此一旦你在列表中发现了你要找的表情符号,你就可以按回车或 tab 键来补全当前高亮的那一项。

Issue autocompletion

Issue 的自动补全

Typing # will bring up a list of Issue and Pull Request suggestions. Type a number or any text to filter the list, then hit tab or enter to complete the highlighted result.

按下 # 将会弹出一个 Issue 和 Pull Request 建议列表。输入数字或任何文本可以不断筛选这个列表,然后按回车或 tab 键可以补全当前高亮的那一项。

Zen Mode (fullscreen) writing

禅意模式(全屏书写模式)

Zen Mode allows you to go fullscreen with your writing. You‘ll find the Zen Mode button on comment, issue, and pull request forms across the site.

禅意模式允许你以全屏模式进行书写。在站内的评论、Issue 和 Pull Request 表单中,你都可以找到禅意模式按钮。

You can also use it when creating and editing files by using the Zen Mode button above the file box.

在创建或编辑文件时,你也可以在文件框顶部找到禅意模式按钮。

Zen Mode offers you two themes to choose from, light or dark. You can change which theme you are using with the switcher at the top right of the window.

禅意模式提供了两种主题可供选择,浅色版和深色版。你可以用窗口右上角的切换按钮来更换当前主题。

Check out the blog post for more information about Zen writing mode.

详情参见 关于禅意模式的博文

References

事件引用

Certain references are auto-linked:

引用特定的事件将会自动创建链接:

* SHA: 16c999e8c71134401a78d4d46435517b2271d6ac

* [email protected]: [email protected]

* User/[email protected]: mojombo/[email protected]c

* #Num: #1

* User#Num: mojombo#1

* User/Project#Num: mojombo/github-flavored-markdown#1

becomes

将被渲染为:

Code

实现

The newline and underscore modification code can be seen in below.

关于换行与下划线的差异实现可参见 这个 Gist

If you find a bug in the rendering, please contact support and let us know.

如果你发现了渲染方面的 bug,请 联系支持团队 让我们知道。


译者后记

GitHub 的这篇文档组织得不是很有条理,也存在一些笔误(已联系支持团队 原文已修正)。

在本文开头提到的案例中,源码和渲染结果并不完全匹配,只能作为有限的参考。此问题已反馈,支持团队也已回复确认,但暂未修复。

推荐阅读


原文版本:2013-07-07 (由于官方 GFM 文档的组织方式发生了较大变动,本文将不再随之改动,重要的功能变化将在评论区补充。)



? Creative Commons BY-NC-ND 3.0   |   我要订阅   |   我要捐助

Emoji 代号速查: http://www.emoji-cheat-sheet.com/

GFM现在支持表格了。

表格

你可以使用若干列文字并于第一行下面用转折号-分开它们,然后用管道符|隔开每一列:

First Header  | Second Header

------------- | -------------

Content Cell  | Content Cell

Content Cell  | Content Cell

为了看上去美观,你也可以在两端加上额外的管道符:

| First Header  | Second Header |

| ------------- | ------------- |

| Content Cell  | Content Cell  |

| Content Cell  | Content Cell  |

注意顶部的虚线不需要准确匹配表头文本的长度:

| Name | Description          |

| ------------- | ----------- |

| Help      | Display the help window.|

| Close     | Closes a window     |

你也可以在其中包括内联Markdown元素,比如链接,加粗,斜体或删除

| Name | Description          |

| ------------- | ----------- |

| Help      | ~~Display the~~ help window.|

| Close     | _Closes_ a window     |

最后,通过在表头行加入冒号:,你可以决定文本是左对齐,右对齐,还是居中:

| Left-Aligned  | Center Aligned  | Right Aligned |

| :------------ |:---------------:| -----:|

| col 3 is      | some wordy text | $1600 |

| col 2 is      | centered        |   $12 |

| zebra stripes | are neat        |    $1 |

一个在最左边的冒号表示一个左对齐的列;一个在最右边的冒号表示一个右对齐的列;两边都有的冒号表示一个居中的列。

最后(这里不再是译文了),加上我自己的一个示范:

水果 单价 数量
苹果 3.00 2
香蕉 2.00 4

注意表格要另隔开一个空行。

GitHub Flavored Markdown

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.

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.

Differences from traditional Markdown

Multiple underscores in words

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

  • 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.

http://example.com

becomes

http://example.com

Strikethrough

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

~~Mistaken text.~~

becomes

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.

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.

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 = Redcarpet.new("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.

Tables

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:

| 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.

HTML

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

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

Further reading

http://jbt.github.io/markdown-editor/ 在线编辑器

来源: <https://github.com/cssmagic/blog/issues/13>

原文地址:https://www.cnblogs.com/lsgxeva/p/8540700.html

时间: 2024-07-30 06:05:12

GitHub 风格的 Markdown 语法的相关文章

Markdown语法整理

Markdown语法整理 目录 6.1.竖杠|下划线-写法 6.2.htmltable写法 5.1.无需列表 5.2.有序列表 5.3.定义型列表 5.4.列表缩进 5.5.包含段落的列表 4.1.页内超链接 4.2.文章内部标题链接 3.1.行内式: 3.2.参考式 3.3.自动连接 一.分级目录 二.斜体与粗体 三.超链接 四.锚点 五.列表 六.表格 说明:本文中中语法里面的代码就是需要写的Markdown语法,展示效果就是最后生成的页面此语法编写和测试环境:windows上使用Markd

github markdown语法

github 支持从markdown文件直接生成静态博客,但是github的markdown语法和markdown有些小地方有区别.而且github只支持 utf-8编码的markdown文件,之前在windows中写的markdown文件,因为没注意编码,保存的时候自动以gb2312保存了,导致每 次都不能正常生成静态博客. 标题 markdown标题使用个数1-6的#开始,顶格写. ### 3级标题 实际展示如下: 3级标题 换行 在github 的markdown中,只需要在行尾加多于2个

Markdown语法(例如:github的readme.md)

大标题 =================================== 大标题一般显示工程名,类似html的\<h1\><br /> 你只要在标题下面跟上=====即可 中标题 ----------------------------------- 中标题一般显示重点项,类似html的\<h2\><br /> 你只要在标题下面输入------即可 ### 小标题 小标题类似html的\<h3\><br /> 小标题的格式如下

GitHub上README写法暨markdown语法解读

原文: GitHub上README写法暨markdown语法解读 自从开始玩GitHub以来,就 越来越 感觉它有爱.最近对它的 README.md 文件颇为感兴趣.便写下这贴,帮助更多的还不会编写README文件的同学们. README文件后缀名为md.md是markdown的缩写,markdown是一种编辑博客的语言.用惯了可视化的博客编辑器(比如CSDN博客,囧),这种编程式的博客编辑方案着实让人眼前一亮.不过貌似并不支持全部的markdown语法.本文内容大部分是我自己摸索,可能有些叙述

Markdown语法 (中文版)

 Markdown语法  Markdown是一种可以使用普通文本编辑器编写的标记语言,通过类似HTML的标记语法,它可以使普通文本内容具有一定的格式. Markdown具有一系列衍生版本,用于扩展Markdown的功能(如表格.脚注.内嵌HTML等等),这些功能原初的Markdown尚不具备,它们能让Markdown转换成更多的格式,例如LaTeX,Docbook.Markdown增强版中比较有名的有Markdown Extra.MultiMarkdown. Maruku等.这些衍生版本要么基于

Markdown语法中文版

文章翻译自Markdown创始人JOHN GRUBER的 个人博客, 英文原文请参见 Markdown Syntax; 原文是用Markdown格式写的, 但是cnblogs不支持Markdown(或者是我不知道), 只能重新排版了, Github原文可以参见这里; 个人水平有限, 如有发现错误, 欢迎通过Github 或者 @乔的果园 联系我修改, 谢谢! 如果您不介意, 欢迎关注我的 微信公众号; 文章是直译的, 难免会有一些晦涩, 望见谅, 对于一些专有名词直译过程中我们约定如下: Bol

Markdown 语法说明

NOTE: This is Simplelified Chinese Edition Document of Markdown Syntax. If you are seeking for English Edition Document. Please refer to Markdown: Syntax. 声明: 这份文档派生(fork)于繁体中文版,在此基础上进行了繁体转简体工作,并进行了适当的润色.此文档用 Markdown 语法编写,你可以到这里查看它的源文件.「繁体中文版的原始文件可以

Pandoc中的Markdown语法

.caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px solid #000; } .table { border-collapse: collapse !important; } .table td, .table th { background-color: #fff !important; } .table-bordered th, .table-bordere

markdown 语法和工具

一 简明语法 来自:  http://maxiang.info/ 二 markdown 语法: https://github.com/rhiokim/haroopad/blob/develop/Syntax.md 三 markdown工具总结: http://appinn.me/d/83 四 windows markdown 工具: cutemarked(推荐) 这个很不错,可以配置github的css样式,可以导出为html和pdf http://cloose.github.io/CuteMa