Added code highlighting support (CodeRay).
h3rald h3rald@h3rald.com
Mon, 13 Sep 2010 14:41:16 +0200
3 files changed,
55 insertions(+),
6 deletions(-)
A
content/styles/_code.scss
@@ -0,0 +1,51 @@
+.code { + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + background-color: #222; + font-family: 'Courier New', 'Terminal', monospace; + color: #E6E0DB; + padding: 20px; + overflow: auto; + font-size: 12px; + margin: 20px 0 20px 0; + pre { + line-height: 1.2em; + margin: 0px; + padding: 0px; } + .no { + font-weight: bold; + color: #595959; + } + .an { + color: #E7BE69; } + .c { + color: #BC9358; + font-style: italic; } + .ch { + color: #509E4F; } + .cl, .co { + color: #FFF; } + .fl { + color: #A4C260; } + .fu { + color: #FFC56D; } + .gv { + color: #D0CFFE; } + .i { + color: #A4C260; } + .il {} + .iv { + color: #D0CFFE; } + .pp { + color: #E7BE69; } + .r { + color: #CB7832; } + .rx, .s { + color: #A4C260; } + .sy { + color: #6C9CBD; } + .ta { + color: #E7BE69; } + .pc { + color: #6C9CBD; } }
M
content/styles/style.scss
→
content/styles/style.scss
@@ -5,3 +5,4 @@ @import "_content.scss";
@import "_fancybox.scss"; @import "_fancybox-gallery.scss"; @import "_vendor.scss"; +@import "_code.scss";
M
lib/highlighter.rb
→
lib/highlighter.rb
@@ -1,18 +1,15 @@
- # Monkey patch Nanoc::Helpers::Filtering +require 'coderay' module Nanoc3::Helpers::Filtering def highlight(syntax, &block) - # Seamlessly ripped off from the filter method... - # Capture block data = capture(&block) # Reconvert <% %> data.gsub! /<%/, '<%' data.gsub! /%>/, '%>' - # Filter captured data - filtered_data = "\n<notextile>"+Albino.colorize(data, syntax)+"</notextile>\n" rescue data - # Append filtered data to buffer + filtered_data = CodeRay.scan(data.strip, syntax).div(:line_numbers => :inline, :tab_width => 2, :css =>:class) + filtered_data = "<notextile>\n"+filtered_data+"\n</notextile>" buffer = eval('_erbout', block.binding) buffer << filtered_data end