Welcome to mirror list, hosted at ThFree Co, Russian Federation.

common_mark.rb « plugins « rouge « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8f9de061124b70bb11d63290a99c70473f49cad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# A rouge plugin for CommonMark markdown engine.
# Used to highlight code generated by CommonMark.

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

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

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