Octopress

A blogging framework for hackers.

Backtick Code Blocks

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.

Syntax

``` [language] [title] [url] [link text] [linenos:false] [start:#] [mark:#,#-#]
code snippet
```

Basic options

  • [language] - Used by the syntax highlighter. Passing 'plain' disables highlighting. (Supported languages.)
  • [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'.

Additional options:

These options don't depend on any previous option and order does not matter.

  • start:# - Line numbers begin at # (useful for using snippets to reference longer code).
  • mark:#,#-# - Mark one or more lines of code with the class name "marked". Accepts one number, numbers separated by commas, and number ranges. Example mark:1,5-8 will mark lines 1,5,6,7,8. Note: If you've changed the beginning line number be sure these match rendered line numbers
  • linenos:false - Do not add line numbers to highlighted code.

Examples

1. Here's an example without setting the language.

$ git clone git@github.com:imathis/octopress.git # fork octopress

The source:

```
$ git clone git@github.com:imathis/octopress.git # fork octopress
```

2. This example uses syntax highlighting and a code link.

Discover if a number is primelink
class Fixnum
def prime?
('1' * self) !~ /^1?$|^(11+?)\1+$/
end
end

The source:

``` 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
```

3. This example uses a custom starting line number and marks lines 52 and 54 through 55.

Coffeescript Tricks
# Given an alphabet:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# Iterate over part of the alphabet:
console.log letter for letter in alphabet[4..8]

The source:

``` 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]
```

Other ways to embed code snippets

You might also like to embed code from a file or embed GitHub gists.