GitHub 风格的 Markdown 语法

2023-01-28 0 424

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 youre not already familiar with Markdown, take a look at

Markdown Basics

. If youd 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 句法此基础

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

http://example.com

becomes将被渲染为:

http://example.com

Strikethrough 删除线

GFM adds syntax to create strikethrough text, which is missing from standard Markdown.GFM 减少了删除线句法,补上了国际标准 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 wont need to indent it by four spaces. Note that although fenced code blocks dont 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 源码的可读性更好。

Heres 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 well run it through syntax highlighting. For example, to syntax highlight Ruby code:关于代码块的技巧还不止于此,你还能为代码块指定句法着色效果。在围栏式代码块中,你能指定一个可选的语言标识符,然后我们就能为它启用句法着色了。比如说,这样能为一段 Ruby 代码着色:

“`rubyrequire redcarpetmarkdown = 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 文件

中查证哪些语言标识符是有效的。

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 CellContent 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 dont 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.在横线

最左侧

加冒号表示该列一律左对齐;在横线

最右侧

加冒号表示该列一律右对齐;在横线

两端

加冒号表示该列一律居中对齐。

HTML

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

这个项目中找到一份完整的清单。

举报/反馈

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务