2011-09-08 00:31:08 -04:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
title: "Backtick Code Blocks"
|
|
|
|
date: 2011-07-26 23:42
|
|
|
|
sidebar: false
|
|
|
|
footer: false
|
|
|
|
---
|
|
|
|
|
|
|
|
With the `backtick_codeblock` filter you can use Github's lovely back tick syntax highlighting blocks.
|
|
|
|
Simply start a line with three back ticks followed by a space and the language you're using.
|
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
## Syntax
|
2011-09-08 00:31:08 -04:00
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
``` [language] [title] [url] [link text] [linenos:false] [start:#] [mark:#,#-#]
|
2011-09-08 00:31:08 -04:00
|
|
|
code snippet
|
|
|
|
```
|
2012-06-03 01:24:03 -04:00
|
|
|
### Basic options
|
|
|
|
|
2012-12-20 14:51:47 -05:00
|
|
|
- `[language]` - Used by the syntax highlighter. Passing 'plain' disables highlighting. ([Supported languages](http://pygments.org/docs/lexers/).)
|
2012-06-03 01:24:03 -04:00
|
|
|
- `[title]` - Add a figcaption to your code block.
|
|
|
|
- `[url]` - Download or reference link for your code.
|
|
|
|
- `[Link text]` - Text for the link, defaults to 'link'.
|
|
|
|
|
|
|
|
{% render_partial docs/plugins/_partials/options.markdown %}
|
2011-09-08 00:31:08 -04:00
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
## Examples
|
2011-09-08 00:31:08 -04:00
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
**1.** Here's an example without setting the language.
|
|
|
|
|
|
|
|
```
|
|
|
|
$ sudo make me a sandwich
|
|
|
|
```
|
|
|
|
|
|
|
|
*The source:*
|
2011-09-08 00:31:08 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
$ sudo make me a sandwich
|
|
|
|
```
|
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
**2.** This example uses syntax highlighting and a code link.
|
|
|
|
|
|
|
|
``` ruby Discover if a number is prime http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/ Source Article
|
|
|
|
class Fixnum
|
|
|
|
def prime?
|
|
|
|
('1' * self) !~ /^1?$|^(11+?)\1+$/
|
|
|
|
end
|
|
|
|
end
|
2011-09-08 00:31:08 -04:00
|
|
|
```
|
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
*The source:*
|
2011-09-08 00:31:08 -04:00
|
|
|
|
|
|
|
``` ruby Discover if a number is prime http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/ Source Article
|
|
|
|
class Fixnum
|
|
|
|
def prime?
|
|
|
|
('1' * self) !~ /^1?$|^(11+?)\1+$/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
**3.** This example uses a custom starting line number and marks lines 52 and 54 through 55.
|
|
|
|
|
|
|
|
``` coffeescript Coffeescript Tricks start:51 mark:52,54-55
|
|
|
|
# Given an alphabet:
|
|
|
|
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
|
|
|
# Iterate over part of the alphabet:
|
|
|
|
console.log letter for letter in alphabet[4..8]
|
2011-09-08 00:31:08 -04:00
|
|
|
```
|
2012-05-27 03:04:45 -04:00
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
*The source:*
|
2012-05-27 03:04:45 -04:00
|
|
|
|
2012-05-28 05:22:41 -04:00
|
|
|
``` coffeescript Coffeescript Tricks start:51 mark:52,54-55
|
2012-05-27 03:04:45 -04:00
|
|
|
# Given an alphabet:
|
|
|
|
alphabet = 'abcdefghijklmnopqrstuvwxyz'
|
|
|
|
|
|
|
|
# Iterate over part of the alphabet:
|
|
|
|
console.log letter for letter in alphabet[4..8]
|
|
|
|
```
|
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
### Other ways to embed code snippets
|
2012-05-27 03:04:45 -04:00
|
|
|
|
2012-06-03 01:24:03 -04:00
|
|
|
You might also like to [embed code from a file](/docs/plugins/include-code) or [embed GitHub gists](/docs/plugins/gist-tag).
|