Sha256: 73ed54cb79035751e9d07883341cbba1637e8a91987a29b7e692dc2b55683482

Contents?: true

Size: 719 Bytes

Versions: 8

Compression:

Stored size: 719 Bytes

Contents

# this file is not require'd from the root.  To use this plugin, run:
#
#    require 'rouge/plugins/redcarpet'

# stdlib
require 'cgi'

module Rouge
  module Plugins
    module Redcarpet
      def block_code(code, language)
        lexer = Lexer.find_fancy(language, code) || Lexers::Text

        # XXX HACK: Redcarpet strips hard tabs out of code blocks,
        # so we assume you're not using leading spaces that aren't tabs,
        # and just replace them here.
        if lexer.tag == 'make'
          code.gsub! /^    /, "\t"
        end

        formatter = Formatters::HTML.new(
          :css_class => "highlight #{lexer.tag}"
        )

        formatter.format(lexer.lex(code))
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rouge-0.2.9 lib/rouge/plugins/redcarpet.rb
rouge-0.2.8 lib/rouge/plugins/redcarpet.rb
rouge-0.2.7 lib/rouge/plugins/redcarpet.rb
rouge-0.2.6 lib/rouge/plugins/redcarpet.rb
rouge-0.2.5 lib/rouge/plugins/redcarpet.rb
rouge-0.2.4 lib/rouge/plugins/redcarpet.rb
rouge-0.2.3 lib/rouge/plugins/redcarpet.rb
rouge-0.2.2 lib/rouge/plugins/redcarpet.rb