From dc468e8aef72ec9e85684f458d1f3cc0565ba8bd Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Fri, 12 Mar 2010 14:22:16 +0100 Subject: [PATCH] Syntax coloration as before --- Rules | 1 + config.yaml | 1 + lib/ultraviolet.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/ultraviolet.rb diff --git a/Rules b/Rules index a8fdb435d..2bede5456 100644 --- a/Rules +++ b/Rules @@ -57,6 +57,7 @@ compile '/html/*' do filter :yabbreviations filter :multicorps filter :firsthi + filter :ultraviolet layout 'default' unless item[:layout] == "none" end diff --git a/config.yaml b/config.yaml index 850e53cc5..b71acc3f7 100644 --- a/config.yaml +++ b/config.yaml @@ -4,6 +4,7 @@ data_sources: layouts_root: / type: filesystem_unified output_dir: output +ultraviolet_theme: "twilight" # les langues languages: diff --git a/lib/ultraviolet.rb b/lib/ultraviolet.rb new file mode 100644 index 000000000..a44d032d0 --- /dev/null +++ b/lib/ultraviolet.rb @@ -0,0 +1,43 @@ +class UltraVioletFilter < Nanoc3::Filter + identifier :ultraviolet + def run(content, params={}) + require 'rio' + require 'rubygems' + require 'uv' + code_rule = %r{((.+?))}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=%{
➥ #{filename}
\n} + codesuffix=%{\n
} + 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