GitHub 风格的 Markdown 语法
GitHub 风格的 Markdown 语法
[译] GitHub 风格的 Markdown 语法
- Original: GitHub Flavored Markdown - GitHub Help
- Translated by: cssmagic
声明:原文版权属于 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:
下面这个段落被一个换行符分隔成了两个短语:
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 将忽略单词中的多个下划线。
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 代码着色:
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]
即可(分别表示未完成和已完成)。
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:
引用特定的事件将会自动创建链接:
becomes
将被渲染为:
- SHA: 16c999e
- User@SHA: mojombo@16c999e
- User/Project@SHA: mojombo/github-flavored-markdown@16c999e
- #Num: #1
- User#Num: mojombo#1
- User/Project#Num: mojombo/github-flavored-markdown#1
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 | 我要订阅 | 我要捐助
GFM现在支持表格了。
表格
你可以使用若干列文字并于第一行下面用转折号-
分开它们,然后用管道符|
隔开每一列:
为了看上去美观,你也可以在两端加上额外的管道符:
注意顶部的虚线不需要准确匹配表头文本的长度:
你也可以在其中包括内联Markdown元素,比如链接,加粗,斜体或删除
最后,通过在表头行加入冒号:
,你可以决定文本是左对齐,右对齐,还是居中:
一个在最左边的冒号表示一个左对齐的列;一个在最右边的冒号表示一个右对齐的列;两边都有的冒号表示一个居中的列。
最后(这里不再是译文了),加上我自己的一个示范:
水果 | 单价 | 数量 |
---|---|---|
苹果 | 3.00 | |
香蕉 | 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
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.
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:
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 |
:
For aesthetic purposes, you can also add extra pipes on the ends:
Note that the dashes at the top don't need to match the length of the header text exactly:
You can also include inline Markdown such as links, bold, italics, or strikethrough:
Finally, by including colons :
within the header row, you can define text to be left-aligned, right-aligned, or center-aligned:
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
GitHub 风格的 Markdown 语法的更多相关文章
- GitHub支持的Markdown语法 GitHub Flavored Markdown
GitHub支持的Markdown语法,简称GFM.相比标准的Markdown(SM)语法,有少数几个区别,并添加了新的功能. 本位参考 GitHub Flavored Markdown 撰写.有兴趣 ...
- MarkDownPad Pro 支持github格式的markdown语法
1. http://blog.csdn.net/xiaohei5188/article/details/43964451
- 记录下 Markdown 语法
github上常用markdown语法:Mastering Markdown 目录 0. 目录 1. 锚点 2.标题 3.超链接 3.1.行内式 3.2.自动链接 4.列表 4.1.有序列表 4.2. ...
- Markdown github 风格语法
某些效果cnblog无法支持,见 https://github.com/tanghammer/note/blob/master/Markdown%20github%E9%A3%8E%E6%A0%BC% ...
- GitHub上Markdown语法的高级应用
高级语法格式 本篇的内容来源于Github使用高级格式写作.如果在观看时有什么问题,可以直接查阅源文件.另外需要说明的是Git对Markdown的支持增加了一些扩展功能,因此在Git上可以渲染的Mar ...
- GitHub上README写法暨markdown语法解读
原文: GitHub上README写法暨markdown语法解读 自从开始玩GitHub以来,就 越来越 感觉它有爱.最近对它的 README.md 文件颇为感兴趣.便写下这贴,帮助更多的还不会编写R ...
- 【03】github的markdown语法
[03]github的markdown语法 https://guides.github.com/features/mastering-markdown/(下图)(魔芋:已录入) http://ma ...
- github markdown语法及使用
历史 Markdown是一种轻量级标记语言,创始人为约翰·格鲁伯(英语:John Gruber).它允许人们"使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML(或者HTML)文档 ...
- 2015年12月03日 GitHub入门学习(五)Markdown语法简介
Markdown一种标记语言,语法简洁,不像Word或Pages有大量排版.字体设置.常用的标记符号不超过十个.被大量写作爱好者.撰稿人.作家所青睐. 一.Markdown的优点 专注你的文字内容而不 ...
随机推荐
- zabbix 4.2 安装教程
1.我这里使用的是ali的yum源 #wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7 ...
- 简要说明 django restframework 的交互式文档
现在为了解决前后端交互沟通的问题,不少框架都推出了相关的swage库, 用起来似乎很是友好. 正好最近在开发一个小项目,想到新项目就用新版本新技术的理念,我下载了restframework 3.7的版 ...
- git点滴
git指定版本,SHA-1短的,长的都可以 git checkout c66a9be git checkout c66a9befsadf1sdf1s3fd21 git log ##查询本地log gi ...
- shiro框架在springboot项目中的应用
地址:https://blog.csdn.net/taojin12/article/details/88343990 地址2:https://blog.csdn.net/bicheng4769/art ...
- error: call of overloaded ‘sqrt(double&)’ is ambiguous
OpenFOAM定义了新的sqrt,当引入新的Library时,必须显式地使用std::sqrt(),否则会报如下错误: error: call of overloaded 'sqrt(double& ...
- CSS基础知识总结之css样式引用的三种方式
在html中增加css样式有三种: 1.在标签中增加style属性: <!DOCTYPE html> <html lang="en" xmlns="ht ...
- FMDB复习
// colum/列/字段// row/行/记录// 主键的作用是唯一标识一条记录// sql语句注意:不区分大小写,以分号结束(不要分号也行?) // 如果增加字段,可能要指定数据类型,S ...
- php stripos()函数 语法
php stripos()函数 语法 作用:寻找字符串中某字符最先出现的位置,不区分大小写.直线电参数 语法:stripos(string,find,start) 参数: 参数 描述 string ...
- CSS中浮动属性float及清除浮动
1.float属性 CSS 的 Float(浮动),会使元素向左或向右移动,由于浮动的元素会脱离文档流,所以它后面的元素会重新排列. 浮动元素之后的那些元素将会围绕它,而浮动元素之前的元素将不会受到影 ...
- Maven安装本地jar包至本地repository
1.安装jar包 Maven 安装 JAR 包的命令是: mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -Dartifa ...