Sha256: bee1d83047c6f51a0a384787a7ef48b56d9c6d5cf97402adc1f12aafac484ed6

Contents?: true

Size: 696 Bytes

Versions: 22

Compression:

Stored size: 696 Bytes

Contents

# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Formatters
    class HTMLLineHighlighter < Formatter
      tag 'html_line_highlighter'

      def initialize(delegate, opts = {})
        @delegate = delegate
        @highlight_line_class = opts.fetch(:highlight_line_class, 'hll')
        @highlight_lines = opts[:highlight_lines] || []
      end

      def stream(tokens)
        token_lines(tokens).with_index(1) do |line_tokens, lineno|
          line = %(#{@delegate.format(line_tokens)}\n)
          line = %(<span class="#{@highlight_line_class}">#{line}</span>) if @highlight_lines.include? lineno
          yield line
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
rouge-4.5.1 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.5.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.4.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.3.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.2.1 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.2.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.1.3 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.1.2 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.1.1 lib/rouge/formatters/html_line_highlighter.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/formatters/html_line_highlighter.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/formatters/html_line_highlighter.rb
rouge-4.1.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.0.1 lib/rouge/formatters/html_line_highlighter.rb
rouge-4.0.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-3.30.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-3.29.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-3.28.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-3.27.0 lib/rouge/formatters/html_line_highlighter.rb
rouge-3.26.1 lib/rouge/formatters/html_line_highlighter.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/html_line_highlighter.rb