Syntax Highlighting
Posted
08.03.2010 um 21:54
von
badboy_
-
0 Kommentare
So! Ab sofort gibt es hier im Blog auch Syntax Highlighting.
Möglich macht das SHJS:
SHJS is a JavaScript program which highlights source code passages in HTML documents. Documents using SHJS are highlighted on the client side by the web browser.
Auf Serverseite erledigt folgendes Stück Code die Arbeit:
html = Nokogiri::XML.parse(html_code)
html.css('pre').each do |pre|
pre.css('code').each do |code|
out = code.text
lines = out.split("\n")
if lines.first[0, 3] == '@@@'
lang = lines.shift.gsub('@@@', '').strip
pre.set_attribute('class', 'sh_' + lang)
code.content = lines.join("\n")
end
end
end
Das habe ich aus dem Code zu showoff: showoff.rb:86
Als Grundlage für das Layout habe ich das Theme "ide-devcpp" genommen und modifiziert. Die modifizierte Version könnt ihr ja einfach aus dem production-System nehmen: sh_vibrantink_like.css.
Angelehnt ist das Theme an das vim-Colorscheme vibrantink.
0 Kommentare: