Sha256: 2e87fad027e942cb86ce7cea551e6ec7495f3e17edb531e3dd7e83b8b6d1a21a

Contents?: true

Size: 1.11 KB

Versions: 206

Compression:

Stored size: 1.11 KB

Contents

require 'nokogiri'
require "coderay"

module CodeRay
  class << self
    alias :orig_scan :scan
    # Override the coderay scan method to remove escaped underscores prior
    # to passing over
    def scan(*args)
      args.first.gsub!("\\_", "_")
      orig_scan(*args)
    end
  end
end

class CodeblocksFilter < Nanoc::Filter
  identifier :codeblocks

  def run(content, params={})
    doc = Nokogiri::HTML.fragment(content)
    # Remove any escaped underscores from code blocks that are not marked
    # up by coderay
    doc.search('code').each do |n|
      n.content = n.content.gsub("\\_", "_")
    end
    # Same for coderay markup, not sure if this will apply always,
    # but seems to deal with highlighted Ruby
    # Keeping for future reference, but now replaced by remove underscores
    # prior to passing to coderay above
    #doc.search('.CodeRay .code').each do |n|
    #  n.xpath("//text()[. = '\\_']").each do |n|
    #    n.content = n.content.gsub("\\_", "_")
    #  end
    #  n.xpath("//text()[. = '\\']").each do |n|
    #    n.content = n.content.gsub("\\", "")
    #  end
    #end
    doc.to_html
  end

end

Version data entries

206 entries across 206 versions & 1 rubygems

Version Path
origen-0.60.18 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.17 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.16 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.14 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.13 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.12 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.11 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.10 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.9 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.8 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.7 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.6 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.5 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.4 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.3 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.2 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.1 templates/nanoc/lib/codeblocks_filter.rb
origen-0.60.0 templates/nanoc/lib/codeblocks_filter.rb
origen-0.59.8 templates/nanoc/lib/codeblocks_filter.rb
origen-0.59.7 templates/nanoc/lib/codeblocks_filter.rb