Hi all,
JavaScript-based syntax highlighting sucks, and we all know it. Here's
a little snippet to use coderay instead, make sure you do 'sudo gem
install coderay' first.
This probably has some bugs, and obviously needs some styling love,
but it's a much better solution, and fiddling with brittle JS-based
syntax highlighters.
Here's a quick screenshot of a bit of scripty2 documentation generated
this way:
http://tr.im/oaxD
What do you guys think?
require 'coderay'
class BlueCloth
CodeBlockClassNameRegexp = /(?:\s*lang(?:uage)?:\s*(\w+)\s*\n)(.*)/
def transform_code_blocks( str, rs )
@log.debug " Transforming code blocks"
class_name = "javascript"
str.gsub( CodeBlockRegexp ) do |block|
codeblock = $1
remainder = $2
codeblock = codeblock.sub( CodeBlockClassNameRegexp ) do |b|
class_name = $1
$2
end
CodeRay.scan( outdent(codeblock).rstrip, :javascript ).div
end
end
end
Best,
Thomas