Syntax coloration as before

This commit is contained in:
Yann Esposito (Yogsototh) 2010-03-12 14:22:16 +01:00
parent 3e4d181219
commit dc468e8aef
3 changed files with 45 additions and 0 deletions

1
Rules
View file

@ -57,6 +57,7 @@ compile '/html/*' do
filter :yabbreviations
filter :multicorps
filter :firsthi
filter :ultraviolet
layout 'default' unless item[:layout] == "none"
end

View file

@ -4,6 +4,7 @@ data_sources:
layouts_root: /
type: filesystem_unified
output_dir: output
ultraviolet_theme: "twilight"
# les langues
languages:

43
lib/ultraviolet.rb Normal file
View file

@ -0,0 +1,43 @@
class UltraVioletFilter < Nanoc3::Filter
identifier :ultraviolet
def run(content, params={})
require 'rio'
require 'rubygems'
require 'uv'
code_rule = %r{(<code class="(.+?)"( file="(.+?)")?>(.+?)</code>)}m
content.gsub!(code_rule) do |full|
# original, lang, filename, code = full[0], full[1], full[3], full[4]
original, lang, filename, code = $1, $2, $4, $5
if lang =~ /^(zsh|bash|sh|csh|shell)$/
lang='shell-unix-generic'
end
# Create a plaintext file version for download.
codeprefix=''
codesuffix=''
if filename
webpath = @item.path
code_path = [ 'output' , webpath, 'code']
url = webpath + 'code/' + filename
if (url == @url)
puts %{erreur de redo : #{url}}
break
end
@url=url
copy_text_to_file(code, filename, code_path)
codeprefix=%{<div class="file"><a href="#{url}"> &#x27A5; #{filename} </a></div><div class="withfile">\n}
codesuffix=%{\n</div>}
end
# Substitute the un-highlighted code with the highlighted code.
codeprefix+Uv.parse(code, "xhtml", lang, false, @config[:ultraviolet_theme])+codesuffix
end
content
end
private
def copy_text_to_file(str, fname, dir)
dest_rio = rio(dir).mkpath
frio = rio(dir, fname).delete
frio << str
puts "\t\twrote file #{dir}/#{fname}"
end
end