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

disable_escape!, enable_escape!, #escape?, escape_enabled?, #filter_escapes, find, format, #format, #render, tag, with_escape

Constructor Details

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

Returns a new instance of HTMLLinewise.



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

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

Instance Method Details

#stream(tokens, &b) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rouge/formatters/html_linewise.rb', line 20

def stream(tokens, &b)
  token_lines(tokens).with_index(1) do |line_tokens, lineno|
    yield %(<#{@tag_name} class="#{sprintf @class_format, lineno}">)
    line_tokens.each do |tok, val|
      yield @formatter.span(tok, val)
    end
    yield %(\n</#{@tag_name}>)
  end
end