Sha256: 03c07ecedf5026e959e59603ab4ebea75cb45d7d9111a24ce72089ac7cdd7692

Contents?: true

Size: 630 Bytes

Versions: 2

Compression:

Stored size: 630 Bytes

Contents

# coding: utf-8

require 'redcarpet'
require 'pygments'
require 'coderay'
require 'set'

module Retter
  module Renderers
    class CodeRayRenderer < Redcarpet::Render::HTML
      def block_code(code, lang)
        CodeRay.scan(code, lang ? lang.intern : :plain).div
      end
    end

    class PygmentsRenderer < Redcarpet::Render::HTML
      LANGUAGES = Set.new(Pygments.lexers.map {|_, l| l[:aliases] }.flatten)

      def block_code(code, lang)
        lang = LANGUAGES.include?(lang) ? lang : 'text'

        Pygments.highlight(code, lexer: lang, formatter: 'html', options: {encoding: 'utf-8'})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
retter-0.2.2 lib/retter/renderers.rb
retter-0.2.1 lib/retter/renderers.rb