Sha256: a76ef1e90d06132f964b42f89445b891ee949fb0522f90723a78ff6fea910922

Contents?: true

Size: 841 Bytes

Versions: 14

Compression:

Stored size: 841 Bytes

Contents

# -*- coding: utf-8 -*- #

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

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

        # 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 = rouge_formatter(lexer)
        formatter.format(lexer.lex(code))
      end

      # override this method for custom formatting behavior
      def rouge_formatter(lexer)
        Formatters::HTML.new(:css_class => "highlight #{lexer.tag}")
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
rouge-1.11.1 lib/rouge/plugins/redcarpet.rb
rouge-1.11.0 lib/rouge/plugins/redcarpet.rb
rouge-1.10.1 lib/rouge/plugins/redcarpet.rb
rouge-1.10.0 lib/rouge/plugins/redcarpet.rb
gitlab-rouge-1.9.2 lib/rouge/plugins/redcarpet.rb
rouge-1.9.1 lib/rouge/plugins/redcarpet.rb
rouge-1.9.0 lib/rouge/plugins/redcarpet.rb
rouge-1.8.0 lib/rouge/plugins/redcarpet.rb
rouge-1.7.7 lib/rouge/plugins/redcarpet.rb
rouge-1.7.4 lib/rouge/plugins/redcarpet.rb
rouge-1.7.3 lib/rouge/plugins/redcarpet.rb
rouge-1.7.2 lib/rouge/plugins/redcarpet.rb
rouge-1.7.1 lib/rouge/plugins/redcarpet.rb
rouge-1.7.0 lib/rouge/plugins/redcarpet.rb