Class: Rouge::Formatters::HTMLLinewise

Inherits:
Rouge::Formatter show all
Defined in:
lib/rouge/formatters/html_linewise.rb

Constant Summary

Constants inherited from Rouge::Formatter

Rouge::Formatter::REGISTRY

Instance Method Summary collapse

Methods inherited from Rouge::Formatter

find, format, #format, #render, tag

Constructor Details

#initialize(formatter, opts = {}) ⇒ HTMLLinewise

Returns a new instance of HTMLLinewise.



6
7
8
9
# File 'lib/rouge/formatters/html_linewise.rb', line 6

def initialize(formatter, opts={})
  @formatter = formatter
  @class_format = opts.fetch(:class, 'line-%i')
end

Instance Method Details

#next_line_classObject



21
22
23
24
# File 'lib/rouge/formatters/html_linewise.rb', line 21

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

#stream(tokens, &b) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rouge/formatters/html_linewise.rb', line 11

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