[关闭]
@lumincinta 2017-01-31T14:08:37.000000Z 字数 3839 阅读 382

GitHub: Working with advanced formatting

Markdown GitHub


Working with advanced formatting

Formatting like tables, syntax highlighting, and automatic linking allows you to arrange complex information clearly in your pull requests, issues, and comments.

Organizing information with tables

You can build tables to organize information in comments, issues, pull requests, and wikis.

Creating and highlighting code blocks

Share samples of code with fenced code blocks and enabling syntax highlighting.

Autolinked references and URLS

References to URLs, issues, pull requests, and commits are automatically shortened and converted into links.


Organizing information with tables

You can build tables to organize information in comments, issues, pull requests, and wikis.

Creating a table

You can create tables with pipes | and hyphens -. Hyphens are used to create each column's header, while pipes separate each column.

  1. | First Header | Second Header |
  2. | ------------- | ------------- |
  3. | Content Cell | Content Cell |
  4. | Content Cell | Content Cell |

Rendered table

The pipes on either end of the table are optional.

Cells can vary in width and do not need to be perfectly aligned within columns. There must be at least three hyphens in each column of the header row.

  1. | Command | Description |
  2. | --- | --- |
  3. | git status | List all new or modified files |
  4. | git diff | Show file differences that haven't been staged |

Rendered table with varied cell width

Formatting content within your table

You can use formatting such as links, inline code blocks, and text styling within your table:

  1. | Command | Description |
  2. | --- | --- |
  3. | `git status` | List all *new or modified* files |
  4. | `git diff` | Show file differences that **haven't been** staged |

Rendered table with formatted text

You can align text to the left, right, or center of a column by including colons : to the left, right, or on both sides of the hyphens within the header row.

  1. | Left-aligned | Center-aligned | Right-aligned |
  2. | :--- | :---: | ---: |
  3. | git status | git status | git status |
  4. | git diff | git diff | git diff |

Rendered table with left, center, and right text alignment

To include a pipe | as content within your cell, use a \ before the pipe:

  1. | Name | Character |
  2. | --- | --- |
  3. | Backtick | ` |
  4. | Pipe | \| |

Rendered table with an escaped pipe

Further reading


Creating and highlighting code blocks

Share samples of code with fenced code blocks and enabling syntax highlighting.

Fenced code blocks

You can create fenced code blocks by placing triple backticks ````` before and after the code block. We recommend placing a blank line before and after code blocks to make the raw formatting easier to read.

  1. ```
  2. function test() {
  3. console.log("notice the blank line before this function?");
  4. }
  5. ​```

Rendered fenced code block

Tip: To preserve your formatting within a list, make sure to indent non-fenced code blocks by eight spaces.

Syntax highlighting

You can add an optional language identifier to enable syntax highlighting in your fenced code block.

For example, to syntax highlight Ruby code:

  1. ```ruby
  2. require 'redcarpet'
  3. markdown = Redcarpet.new("Hello World!")
  4. puts markdown.to_html
  5. ​```

Rendered code block with Ruby syntax highlighting

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

Further reading


Autolinked references and URLs

References to URLs, issues, pull requests, and commits are automatically shortened and converted into links.

URLs

GitHub automatically creates links from standard URLs.

Visit https://github.com

Rendered autolinked URL

For more information on creating links, see "Basic writing and formatting syntax."

Issues and pull requests

Within repositories, references to issues and pull requests are automatically converted to shortened links to the issue or pull request.

Reference type Raw reference Short link
Issue or pull request URL https://github.com/jlord/sheetsee.js/issues/26 #26
# and issue or pull request number 26 #26
GH- and issue or pull request number GH-26 GH-26
Username/Repository# and issue or pull request number jlord/sheetsee.js#26 jlord/sheetsee.js#26

Commit SHAs

References to a commit's SHA hash are automatically converted into shortened links to the commit on GitHub.

Reference type Raw reference Short link
Commit URL https://github.com/jlord/sheetsee.js/commit/a5c3785ed8d6a35868bc169f07e40e889087fd2e a5c3785
SHA a5c3785ed8d6a35868bc169f07e40e889087fd2e a5c3785
User@SHA jlord@a5c3785ed8d6a35868bc169f07e40e889087fd2e jlord@a5c3785
Username/Repository@SHA User/Repository@SHA: jlord/sheetsee.js@a5c3785ed8d6a35868bc169f07e40e889087fd2e jlord/sheetsee.js@a5c3785

Further reading

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注