Sha256: eac5ef48c52f319922826b1099b1d1a2c0f5d8219a29acce6f3e15714bd867c1

Contents?: true

Size: 647 Bytes

Versions: 2

Compression:

Stored size: 647 Bytes

Contents

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

module Rouge
  module Formatters
    class HTMLLinewise < Formatter
      def initialize(formatter, opts={})
        @formatter = formatter
        @class_format = opts.fetch(:class, 'line-%i')
      end

      def stream(tokens, &b)
        token_lines(tokens) do |line|
          yield "<div class=#{next_line_class}>"
          line.each do |tok, val|
            yield @formatter.span(tok, val)
          end
          yield '</div>'
        end
      end

      def next_line_class
        @lineno ||= 0
        sprintf(@class_format, @lineno += 1).inspect
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rouge-alda-3.3.0 lib/rouge/formatters/html_linewise.rb
rouge-3.3.0 lib/rouge/formatters/html_linewise.rb