Using CodeRay to replace JS-based syntax highlighting

31 views
Skip to first unread message

madrobby

unread,
Jun 11, 2009, 12:11:44 PM6/11/09
to PDoc
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

Tobie Langel

unread,
Jun 11, 2009, 12:23:55 PM6/11/09
to pd...@googlegroups.com
If I recall correctly, either Samuel or Sébastien already committed a
similar patch.
Reply all
Reply to author
Forward
0 new messages