Added Ace::PygmentsFilter for syntax highlighting via pygments.org's pygmentize.
This commit is contained in:
parent
6860bd4705
commit
9f128f8fed
1 changed files with 19 additions and 0 deletions
19
lib/ace/filters/pygments.rb
Normal file
19
lib/ace/filters/pygments.rb
Normal 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
|
Loading…
Add table
Reference in a new issue