class Content::Pipeline::Filters::Code
Constants
- Matcher
- Templates
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Content::Pipeline::Filter::new
# File lib/content/pipeline/filters/code.rb, line 17 def initialize(*args) super( *args ) end
Private Instance Methods
highlight()
click to toggle source
# File lib/content/pipeline/filters/code.rb, line 24 def highlight @str = @str.to_nokogiri_fragment @str.search("pre > code").each do |node| lang = node[:class] || node.parent[:lang] || \ @opts[:default] || "ruby" node.parent.replace( Templates[:wrap] % [ lang, lang, lang, pygments(node.inner_text, lang) ] ) end end
pygments(str, lang)
click to toggle source
# File lib/content/pipeline/filters/code.rb, line 39 def pygments(str, lang) return str if jruby? || !Pygments::Lexer[lang] Pygments::Lexer[lang].highlight(str) =~ Matcher ? $1 : str end