Markdown
GitLab Flavored Markdown (GFM) 中文测试
Note:
Not all of the GitLab-specific extensions to Markdown that are described in
this document currently work on our documentation website.For the best result, we encourage you to check this document out as rendered
by GitLab: markdown.md
GitLab uses (as of 11.1) the CommonMark Ruby Library for Markdown processing of all new issues, merge requests, comments, and other Markdown content in the GitLab system. Previous content and Markdown files .md
in the repositories are still processed using the Redcarpet Ruby library.
Where there are significant differences, we will try to call them out in this document.
GitLab uses "GitLab Flavored Markdown" (GFM). It extends the standard Markdown in a few significant ways to add some useful functionality. It was inspired by GitHub Flavored Markdown.
You can use GFM in the following areas:
- comments
- issues
- merge requests
- milestones
- snippets (the snippet must be named with a
.md
extension) - wiki pages
- markdown documents inside the repository (currently only rendered by Redcarpet)
You can also use other rich text files in GitLab. You might have to install a
dependency to do so. Please see the github-markup gem readme for more information.
Newlines
GFM honors the markdown specification in how paragraphs and line breaks are handled.
A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines.
Line-breaks, or soft returns, are rendered if you end a line with two or more spaces:
Roses are red [followed by two or more spaces]
Violets are blue
Sugar is sweet
Roses are red
Violets are blue
Sugar is sweet
Multiple underscores in words
It is not reasonable to italicize just part of a word, especially when you're dealing with code and names that often appear with multiple underscores. Therefore, GFM ignores multiple underscores in words:
perform_complicated_task
do_this_and_do_that_and_another_thing
perform_complicated_task
do_this_and_do_that_and_another_thing
URL auto-linking
GFM will autolink almost any URL you copy and paste into your text:
* https://www.google.com
* https://google.com/
* ftp://ftp.us.debian.org/debian/
* smb://foo/bar/baz
* irc://irc.freenode.net/gitlab
* http://localhost:3000
- https://google.com/
- ftp://ftp.us.debian.org/debian/
- smb://foo/bar/baz
- irc://irc.freenode.net/gitlab
- http://localhost:3000
Multiline Blockquote
If this is not rendered correctly, see
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/user/markdown.md#multiline-blockquote
On top of standard Markdown blockquotes, which require prepending >
to quoted lines,
GFM supports multiline blockquotes fenced by >>>
:
>>>
If you paste a message from somewhere else
that
spans
multiple lines,
you can quote that without having to manually prepend `>` to every line!
>>>
If you paste a message from somewhere else
that
spans
multiple lines,
you can quote that without having to manually prepend >
to every line!
Code and Syntax Highlighting
If this is not rendered correctly, see
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/user/markdown.md#code-and-syntax-highlighting
GitLab uses the Rouge Ruby library for syntax highlighting. For a
list of supported languages visit the Rouge website.
Blocks of code are either fenced by lines with three back-ticks ```
,
or are indented with four spaces. Only the fenced code blocks support syntax
highlighting:
Inline `code` has `back-ticks around` it.
Inline code
has back-ticks around
it.
Example:
```javascript
var s = "JavaScript syntax highlighting";
alert(s);
```
```python
def function():
#indenting works just fine in the fenced code block
s = "Python syntax highlighting"
print s
```
```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
```
No language indicated, so no syntax highlighting.
s = "There is no highlighting for this."
But let's throw in a <b>tag</b>.
```
becomes:
var s = "JavaScript syntax highlighting";
alert(s);
def function():
#indenting works just fine in the fenced code block
s = "Python syntax highlighting"
print s
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
No language indicated, so no syntax highlighting.
s = "There is no highlighting for this."
But let's throw in a <b>tag</b>.
Task Lists
If this is not rendered correctly, see
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/user/markdown.md#task-lists
You can add task lists to issues, merge requests and comments. To create a task list, add a specially-formatted Markdown list, like so:
- [x] Completed task
- [ ] Incomplete task
- [ ] Sub-task 1
- [x] Sub-task 2
- [ ] Sub-task 3
- [x] Completed task
- [ ] Incomplete task
- [ ] Sub-task 1
- [x] Sub-task 2
- [ ] Sub-task 3
Tasks formatted as ordered lists are supported as well:
1. [x] Completed task
1. [ ] Incomplete task
1. [ ] Sub-task 1
1. [x] Sub-task 2
- [x] Completed task
- [ ] Incomplete task
- [ ] Sub-task 1
- [x] Sub-task 2
Task lists can only be created in descriptions, not in titles. Task item state can be managed by editing the description's Markdown or by toggling the rendered check boxes.
Math
If this is not rendered correctly, see
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/user/markdown.md#math
It is possible to have math written with the LaTeX syntax rendered using KaTeX.
Math written inside $``$
will be rendered inline with the text.
Math written inside triple back quotes, with the language declared as math
, will be rendered on a separate line.
Example:
This math is inline $`a^2+b^2=c^2`$.
This is on a separate line
```math
a^2+b^2=c^2
```
Becomes:
This math is inline (a^2+b^2=c^2).
This is on a separate line
a^2+b^2=c^2
Be advised that KaTeX only supports a subset of LaTeX.
Note:
This also works for the asciidoctor:stem: latexmath
. For details see the asciidoctor user manual.
Standard Markdown
Headers
# H1
## H2
### H3
#### H4
##### H5
###### H6
Alternatively, for H1 and H2, an underline-ish style:
Alt-H1
======
Alt-H2
------
Header IDs and links
All Markdown-rendered headers automatically get IDs, except in comments.
On hover, a link to those IDs becomes visible to make it easier to copy the link to the header to give it to someone else.
The IDs are generated from the content of the header according to the following rules:
- All text is converted to lowercase.
- All non-word text (e.g., punctuation, HTML) is removed.
- All spaces are converted to hyphens.
- Two or more hyphens in a row are converted to one.
- If a header with the same ID has already been generated, a unique
incrementing number is appended, starting at 1.
For example:
# This header has spaces in it
## This header has a :thumbsup: in it
# This header has Unicode in it: 한글
## This header has spaces in it
### This header has spaces in it
## This header has 3.5 in it (and parentheses)
Would generate the following link IDs:
this-header-has-spaces-in-it
this-header-has-a-in-it
this-header-has-unicode-in-it-한글
this-header-has-spaces-in-it
this-header-has-spaces-in-it-1
this-header-has-3-5-in-it-and-parentheses
Note that the Emoji processing happens before the header IDs are generated, so the Emoji is converted to an image which then gets removed from the ID.
Emphasis
Examples:
Emphasis, aka italics, with *asterisks* or _underscores_.
Strong emphasis, aka bold, with **asterisks** or __underscores__.
Combined emphasis with **asterisks and _underscores_**.
Strikethrough uses two tildes. ~~Scratch this.~~
Become:
Emphasis, aka italics, with asterisks or underscores.
Strong emphasis, aka bold, with asterisks or underscores.
Combined emphasis with asterisks and underscores.
Strikethrough uses two tildes. Scratch this.
Lists
Examples:
1. First ordered list item
2. Another item
* Unordered sub-list.
1. Actual numbers don't matter, just that it's a number
1. Ordered sub-list
4. And another item.
* Unordered list can use asterisks
- Or minuses
+ Or pluses
Become:
- First ordered list item
- Another item
- Unordered sub-list.
- Actual numbers don't matter, just that it's a number
- Ordered sub-list
- And another item.
- Unordered list can use asterisks
- Or minuses
- Or pluses
If a list item contains multiple paragraphs,
each subsequent paragraph should be indented to the same level as the start of the list item text (Redcarpet: paragraph should be indented with four spaces.)
Example:
1. First ordered list item
Second paragraph of first item.
2. Another item
Becomes:
-
First ordered list item
Paragraph of first item.
-
Another item
If the paragraph of the first item is not indented with the proper number of spaces,
the paragraph will appear outside the list, instead of properly indented under the list item.
Example:
1. First ordered list item
Paragraph of first item.
2. Another item
Becomes:
- First ordered list item
Paragraph of first item.
- Another item
Links
There are two ways to create links, inline-style and reference-style.
[I'm an inline-style link](https://www.google.com)
[I'm a reference-style link][Arbitrary case-insensitive reference text]
[I'm a relative reference to a repository file](LICENSE)
[I am an absolute reference within the repository](/doc/user/markdown.md)
[I link to the Milestones page](/../milestones)
[You can use numbers for reference-style link definitions][1]
Or leave it empty and use the [link text itself][]
Some text to show that the reference links can follow later.
[arbitrary case-insensitive reference text]: https://www.mozilla.org
[1]: http://slashdot.org
[link text itself]: https://www.reddit.com
Note:
Relative links do not allow referencing project files in a wiki page or wiki
page in a project file. The reason for this is that, in GitLab, wiki is always
a separate Git repository. For example,[I'm a reference-style link](style)
will point the link towikis/style
when the link is inside of a wiki markdown file.
Images
Examples:
Here's our logo (hover to see the title text):
Inline-style:
![alt text](img/markdown_logo.png)
Reference-style:
![alt text1][logo]
[logo]: img/markdown_logo.png
Become:
Here's our logo:
Inline-style:
Reference-style:
Blockquotes
Examples:
> Blockquotes are very handy in email to emulate reply text.
> This line is part of the same quote.
Quote break.
> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
Become:
Blockquotes are very handy in email to emulate reply text.
This line is part of the same quote.
Quote break.
This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can put Markdown into a blockquote.
Inline HTML
You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
See the documentation for HTML::Pipeline's SanitizationFilter class for the list of allowed HTML tags and attributes. In addition to the default SanitizationFilter
whitelist, GitLab allows span
, abbr
, details
and summary
elements.
Examples:
<dl>
<dt>Definition list</dt>
<dd>Is something people use sometimes.</dd>
<dt>Markdown in HTML</dt>
<dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
</dl>
Become:
- Definition list
- Is something people use sometimes.
- Markdown in HTML
- Does *not* work **very** well. Use HTML tags.
Details and Summary
Content can be collapsed using HTML's <details>
and <summary>
tags. This is especially useful for collapsing long logs so they take up less screen space.
Click me to collapse/fold.
These details will remain hidden until expanded.
PASTE LOGS HERE
Note: Markdown inside these tags is supported, as long as you have a blank link after the </summary>
tag and before the </details>
tag, as shown in the example. Redcarpet does not support Markdown inside these tags. You can work around this by using HTML, for example you can use <pre><code>
tags instead of code fences.
<details>
<summary>Click me to collapse/fold.</summary>
These details _will_ remain **hidden** until expanded.
PASTE LOGS HERE
</details>
Horizontal Rule
Examples:
Three or more...
---
Hyphens
***
Asterisks
___
Underscores
Become:
Three or more...
Hyphens
Asterisks
Underscores
Line Breaks
A good way to learn how line breaks work is to experiment and discover -- hit Enter once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. The "Preview" tab is your friend.
Here are some things to try out:
Examples:
Here's a line for us to start with.
This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
This line is also a separate paragraph, but...
This line is only separated by a single newline, so it *does not break* and just follows the previous line in the *same paragraph*.
This line is also a separate paragraph, and...
This line is *on its own line*, because the previous line ends with two spaces. (but still in the *same paragraph*)
spaces.
Become:
Here's a line for us to start with.
This line is separated from the one above by two newlines, so it will be a separate paragraph.
This line is also a separate paragraph, but...
This line is only separated by a single newline, so it does not break and just follows the previous line in the same paragraph.
This line is also a separate paragraph, and...
This line is on its own line, because the previous line ends with two spaces. (but still in the same paragraph)
spaces.
Tables
Tables aren't part of the core Markdown spec, but they are part of GFM.
Example:
| header 1 | header 2 |
| -------- | -------- |
| cell 1 | cell 2 |
| cell 3 | cell 4 |
Becomes:
header 1 | header 2 |
---|---|
cell 1 | cell 2 |
cell 3 | cell 4 |
Note: The row of dashes between the table header and body must have at least three dashes in each column.
By including colons in the header row, you can align the text within that column.
Example:
| Left Aligned | Centered | Right Aligned | Left Aligned | Centered | Right Aligned |
| :----------- | :------: | ------------: | :----------- | :------: | ------------: |
| Cell 1 | Cell 2 | Cell 3 | Cell 4 | Cell 5 | Cell 6 |
| Cell 7 | Cell 8 | Cell 9 | Cell 10 | Cell 11 | Cell 12 |
Becomes:
Left Aligned | Centered | Right Aligned | Left Aligned | Centered | Right Aligned |
---|---|---|---|---|---|
Cell 1 | Cell 2 | Cell 3 | Cell 4 | Cell 5 | Cell 6 |
Cell 7 | Cell 8 | Cell 9 | Cell 10 | Cell 11 | Cell 12 |
Footnotes
Example:
You can add footnotes to your text as follows.[^2]
[^2]: This is my awesome footnote.
Becomes:
You can add footnotes to your text as follows.[1]
The formula for water is H2O while the equation for the theory of relativity is E = mc2.
References
- This document leveraged heavily from the Markdown-Cheatsheet.
- The Markdown Syntax Guide at Daring Fireball is an excellent resource for a detailed explanation of standard markdown.
- Dillinger.io is a handy tool for testing standard markdown.
This is my awesome footnote. ↩︎