Co-authored-by: Matt Pollard <mattpollard@users.noreply.github.com> Co-authored-by: Grace Park <gracepark@github.com> Co-authored-by: Steve Guntrip <12534592+stevecat@users.noreply.github.com> Co-authored-by: Robert Sese <sese@github.com> Co-authored-by: Peter Bengtsson <peterbe@github.com> Co-authored-by: Rachael Sewell <rachmari@github.com>
2.3 KiB
2.3 KiB
title, intro, redirect_from, versions, shortTitle
| title | intro | redirect_from | versions | shortTitle | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Creating and highlighting code blocks | Share samples of code with fenced code blocks and enabling syntax highlighting. |
|
|
Create code blocks |
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.
```
function test() {
console.log("notice the blank line before this function?");
}
```
{% tip %}
Tip: To preserve your formatting within a list, make sure to indent non-fenced code blocks by eight spaces.
{% endtip %}
To display triple backticks in a fenced code block, wrap them inside quadruple backticks.
```` ``` Look! You can see my backticks. ``` ````
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:
```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
We use Linguist to perform language detection and to select third-party grammars for syntax highlighting. You can find out which keywords are valid in the languages YAML file.


