Sha256: 863f638589e494d136583ef2e3e3942227078bfb335e6e2678b17e59f77fdb8a

Contents?: true

Size: 699 Bytes

Versions: 5

Compression:

Stored size: 699 Bytes

Contents

require 'middleman-syntax/formatters'

module Middleman
  module Syntax
    module Highlighter
      mattr_accessor :options

      # A helper module for highlighting code
      def self.highlight(code, language=nil, opts={})
        lexer = Rouge::Lexer.find_fancy(language, code) || Rouge::Lexers::PlainText

        highlighter_options = options.to_h.merge(opts)
        highlighter_options[:css_class] = [ highlighter_options[:css_class], lexer.tag ].join(' ')
        lexer_options = highlighter_options.delete(:lexer_options)

        formatter = Middleman::Syntax::Formatters::HTML.new(highlighter_options)
        formatter.format(lexer.lex(code, lexer_options))
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
middleman-syntax-3.4.0 lib/middleman-syntax/highlighter.rb
middleman-syntax-3.3.0 lib/middleman-syntax/highlighter.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/middleman-syntax-3.0.0/lib/middleman-syntax/highlighter.rb
middleman-syntax-3.2.0 lib/middleman-syntax/highlighter.rb
middleman-syntax-3.0.0 lib/middleman-syntax/highlighter.rb