Added documentation and tests for forcing Pygments lexers with lang:language.

This commit is contained in:
Brandon Mathis 2011-08-21 16:20:10 -04:00
parent 3ea1e4edab
commit 2ff46f3711
4 changed files with 54 additions and 34 deletions

View File

@ -10,7 +10,7 @@ With this plugin you can write blocks of code directly in your posts and optiona
#### Syntax
{{ "{% codeblock [title] [url] [link text]" }} %}
{{ "{% codeblock [title] [lang:language] [url] [link text]" }} %}
#### Example 1
@ -24,7 +24,20 @@ Awesome code snippet
#### Example 2
# Including a file extension in the title enables highlighting
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
{{ "{% codeblock Time to be Awesome - awesome.rb" }} %}
puts "Awesome!" unless lame
{{ "{% endcodeblock" }} %}
@ -33,14 +46,30 @@ Awesome code snippet
puts "Awesome!" unless lame
{% endcodeblock %}
#### Example 3
#### Example 4
# Add an optional URL to enable downloading or linking to source
{{ "{% codeblock Got pain? painreleif.sh http://example.com/painreleief.sh Download it!" }} %}
$ rm -rf ~/PAIN
**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?
{{ "{% endcodeblock" }} %}
{% codeblock Javascript Array Syntax (array.js) https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array MDN Documentation %}
{% 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 %}
var arr1 = new Array(arrayLength);
var arr2 = new Array(element0, element1, ..., elementN);
{% endcodeblock %}

View File

@ -2,6 +2,7 @@
layout: page
title: "Include Code"
date: 2011-07-22 09:13
updated: 201-08-21 16:18
sidebar: false
footer: false
---
@ -12,18 +13,28 @@ use the following tag to embed it in a post.
#### Syntax
{{ "{% include_code [title] url" }} %}
{{ "{% include_code [title] [lang:language] path/to/file" }} %}
#### Example 1
This includes a file from `source/downloads/code/test.js`.
{{ "{% include_code javascripts/test.js" }} %}
{{ "{% include_code test.js" }} %}
{% include_code test.js %}
#### Example 2 (with optional title)
By default the `<figcaption>` will be the filename, but you can add a title before the filepath if you like.
{{ "{% include_code Testing include_code javascripts/test.js" }} %}
{{ "{% include_code Add to_fraction for floats ruby/test.rb" }} %}
This includes a file from `source/downloads/code/javascripts/test.js`. By default the `<figcaption>` will be the filename, but you can add a title before the filepath if you like.
This includes a file from `source/downloads/code/ruby/test.rb`.
#### Demo of Example 2
{% include_code Add to_fraction for floats ruby/test.rb %}
{% include_code Testing include_code javascripts/test.js %}
#### Example 3 (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.
{{ "{% include_code test.coffee lang:coffeescript" }} %}
{% include_code test.coffee lang:coffeescript %}

View File

@ -1,20 +0,0 @@
/**
sample javascript from xui
*/
var undefined,
xui,
window = this,
string = new String('string'),
document = window.document,
simpleExpr = /^#?([\w-]+)$/,
idExpr = /^#/,
tagExpr = /<([\w:]+)/,
slice = function (e) { return [].slice.call(e, 0); };
try { var a = slice(document.documentElement.childNodes)[0].nodeType; }
catch(e){ slice = function (e) { var ret=[]; for (var i=0; e[i]; i++)
ret.push(e[i]); return ret; }; }
window.x$ = window.xui = xui = function(q, context) {
return new xui.fn.find(q, context);
};

View File

@ -28,6 +28,6 @@ done
unset i
{% endcodeblock %}
{% codeblock config.ru %}
{% codeblock config lang:ruby %}
Bunch of ruby code
{% endcodeblock %}