Added Ace::PygmentsFilter for syntax highlighting via pygments.org's pygmentize.

master
hotovson 2011-03-06 19:58:35 +01:00
parent 6860bd4705
commit 9f128f8fed
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
# encoding: utf-8
require "ace/filters"
require "nokogiri"
require "albino"
class PygmentsFilter < Filter
def call(item, content)
puts 'PygmentsFilter ************************'
doc = Nokogiri::HTML(content)
doc.css('pre').each do |pre|
puts "\nWARNING: '#{item.original_path}' - element <pre> not contains attribute 'lang'\n" if pre['lang'].nil?
puts "\nWARNING: '#{item.original_path}' - attribute 'lang' not contains any value\n" if !pre['lang'].nil? && pre['lang'].empty?
puts "*** Syntax highlight using '#{pre['lang']}' lexer" unless pre['lang'].nil? || pre['lang'].empty?
pre.replace Albino.colorize(pre.content, pre['lang']) unless pre['lang'].nil? || pre['lang'].empty?
end
doc
end
end