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.



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

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

Instance Method Details

#next_line_classObject



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

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

#stream(tokens, &b) ⇒ Object



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

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