2011-07-22 17:49:01 -04:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
title: "Codeblock"
|
|
|
|
date: 2011-07-22 09:13
|
|
|
|
sidebar: false
|
|
|
|
footer: false
|
|
|
|
---
|
|
|
|
|
2011-07-22 18:36:49 -04:00
|
|
|
With this plugin you can write blocks of code directly in your posts and optionally add titles and links.
|
2011-07-22 17:49:01 -04:00
|
|
|
|
|
|
|
#### Syntax
|
|
|
|
|
2011-08-21 16:20:10 -04:00
|
|
|
{{ "{% codeblock [title] [lang:language] [url] [link text]" }} %}
|
2011-07-22 17:49:01 -04:00
|
|
|
|
|
|
|
#### Example 1
|
|
|
|
|
|
|
|
{{ "{% codeblock" }} %}
|
|
|
|
Awesome code snippet
|
|
|
|
{{ "{% endcodeblock" }} %}
|
|
|
|
|
|
|
|
{% codeblock %}
|
|
|
|
Awesome code snippet
|
|
|
|
{% endcodeblock %}
|
|
|
|
|
|
|
|
#### Example 2
|
|
|
|
|
2011-08-21 16:20:10 -04:00
|
|
|
You can also add syntax highlighting like this.
|
|
|
|
|
|
|
|
{% raw %}{% codeblock lang:objc %}
|
|
|
|
[rectangle setX: 10 y: 10 width: 20 height: 20];
|
|
|
|
{% endcodeblock %}{% endraw %}
|
|
|
|
|
|
|
|
{% codeblock lang:objc %}
|
|
|
|
[rectangle setX: 10 y: 10 width: 20 height: 20];
|
|
|
|
{% endcodeblock %}
|
|
|
|
|
|
|
|
#### Example 3
|
|
|
|
|
|
|
|
Including a file extension in the title enables highlighting
|
|
|
|
|
2011-07-22 17:49:01 -04:00
|
|
|
{{ "{% codeblock Time to be Awesome - awesome.rb" }} %}
|
|
|
|
puts "Awesome!" unless lame
|
|
|
|
{{ "{% endcodeblock" }} %}
|
|
|
|
|
|
|
|
{% codeblock Time to be Awesome - awesome.rb %}
|
|
|
|
puts "Awesome!" unless lame
|
|
|
|
{% endcodeblock %}
|
|
|
|
|
2011-08-21 16:20:10 -04:00
|
|
|
#### Example 4
|
2011-07-22 17:49:01 -04:00
|
|
|
|
2011-08-21 16:20:10 -04:00
|
|
|
**Note:** Pygments supports many languages, but doesn't recognize some file extensions.
|
|
|
|
Add `lang:your_language` to force a language for highlighting. Here's an example:
|
|
|
|
|
|
|
|
|
|
|
|
{{ "{% codeblock Here's an example .rvmrc file. lang:ruby" }} %}
|
|
|
|
rvm ruby-1.8.6 # ZOMG, seriously? We still use this version?
|
2011-07-22 17:49:01 -04:00
|
|
|
{{ "{% endcodeblock" }} %}
|
|
|
|
|
2011-08-21 16:20:10 -04:00
|
|
|
{% codeblock Here's an example .rvmrc file. lang:ruby %}
|
|
|
|
rvm ruby-1.8.6 # ZOMG, seriously? We still use this version?
|
|
|
|
{% endcodeblock %}
|
|
|
|
|
|
|
|
#### Example 5
|
|
|
|
|
|
|
|
Add an optional URL to enable downloading or linking to source.
|
|
|
|
|
|
|
|
{% raw %}{% 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 %}{% endraw %}
|
|
|
|
|
|
|
|
{% codeblock Javascript Array Syntax lang:js http://j.mp/pPUUmW MDN Documentation %}
|
2011-07-22 17:49:01 -04:00
|
|
|
var arr1 = new Array(arrayLength);
|
|
|
|
var arr2 = new Array(element0, element1, ..., elementN);
|
|
|
|
{% endcodeblock %}
|
|
|
|
|
|
|
|
The last argument `link_text` is optional. You may want to link to a source for download file, or documentation on some other site.
|