Sha256: a49eff1caa17fbe94a82238203e29e7ee028043339cec7eaee4902af45b7315d

Contents?: true

Size: 1.16 KB

Versions: 47

Compression:

Stored size: 1.16 KB

Contents

require 'wunderbar'
require 'coderay'
require 'nokogiri'

# workaround for https://github.com/rubychan/coderay/pull/159
module CodeRay::PluginHost
  alias_method :old_plugin_path, :plugin_path
  def plugin_path *args
    args.first.untaint if args.first == CodeRay::CODERAY_PATH
    old_plugin_path *args
  end
end

module Wunderbar
  class HtmlMarkup
    def _coderay(*args)

      # allow arguments in any order, disambiguate based on type
      lang, string, attrs = :ruby, '', {}
      args.each do |arg|
        case arg
          when Symbol; lang = arg
          when String; string = arg
          when Hash;   attrs = arg
        end
      end

      base = _{ CodeRay.scan(CDATANode.normalize(string), lang).div }

      # remove wrapping divs
      while base.length == 1 and base.first.name == 'div'
        div = base.first.parent.children.pop
        div.children.each {|child| child.parent = base.first.parent}
        base.first.parent.children += base.first.children
        base = div.children
      end

      # add attrs provided to pre element
      if base.length == 1 and base.first.name == 'pre'
        base.first.attrs.merge! attrs
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
wunderbar-1.0.1 lib/wunderbar/coderay.rb
wunderbar-1.0.0 lib/wunderbar/coderay.rb
wunderbar-0.24.4 lib/wunderbar/coderay.rb
wunderbar-0.24.3 lib/wunderbar/coderay.rb
wunderbar-0.24.2 lib/wunderbar/coderay.rb
wunderbar-0.24.1 lib/wunderbar/coderay.rb
wunderbar-0.24.0 lib/wunderbar/coderay.rb
wunderbar-0.23.2 lib/wunderbar/coderay.rb
wunderbar-0.23.1 lib/wunderbar/coderay.rb
wunderbar-0.23.0 lib/wunderbar/coderay.rb
wunderbar-0.22.4 lib/wunderbar/coderay.rb
wunderbar-0.22.3 lib/wunderbar/coderay.rb
wunderbar-0.22.2 lib/wunderbar/coderay.rb
wunderbar-0.22.1 lib/wunderbar/coderay.rb
wunderbar-0.22.0 lib/wunderbar/coderay.rb
wunderbar-0.21.4 lib/wunderbar/coderay.rb
wunderbar-0.21.3 lib/wunderbar/coderay.rb
wunderbar-0.21.2 lib/wunderbar/coderay.rb
wunderbar-0.21.1 lib/wunderbar/coderay.rb
wunderbar-0.21.0 lib/wunderbar/coderay.rb