Octopress

A blogging framework for hackers.

Codeblock

With this plugin you can write blocks of code directly in your posts and optionally add titles and links.

Syntax

{% codeblock [title] [lang:language] [url] [link text] %}
code snippet
{% endcodeblock %}

Example 1

{% codeblock %}
Awesome code snippet
{% endcodeblock %}
1
Awesome code snippet

Example 2

You can also add syntax highlighting like this.

{% codeblock lang:objc %}
[rectangle setX: 10 y: 10 width: 20 height: 20];
{% endcodeblock %}
1
[rectangle setX: 10 y: 10 width: 20 height: 20];

Example 3

Including a file extension in the title enables highlighting

{% codeblock Time to be Awesome - awesome.rb %}
puts "Awesome!" unless lame
{% endcodeblock %}
Time to be Awesome - awesome.rb
1
puts "Awesome!" unless lame

Example 4 (Force Highlighting)

Pygments supports many languages, but doesn’t recognize some file extensions. Add lang:your_language to force highlighting if the filename doesn’t work.

{% codeblock Here's an example .rvmrc file. lang:ruby %}
rvm ruby-1.8.6 # ZOMG, seriously? We still use this version?
{% endcodeblock %}
Here’s an example .rvmrc file.
1
rvm ruby-1.8.6 # ZOMG, seriously? We still use this version?

Example 5

Add an optional URL to enable downloading or linking to source.

{% codeblock Javascript Array Syntax lang:js http://j.mp/pPUUmW MDN Documentation %}
var arr1 = new Array(arrayLength);
var arr2 = new Array(element0, element1, ..., elementN);
{% endcodeblock %}
Javascript Array Syntax MDN Documentation
1
2
var arr1 = new Array(arrayLength);
var arr2 = new Array(element0, element1, ..., elementN);

The last argument link_text is optional. You may want to link to a source for download file, or documentation on some other site.