Class: Rouge::Formatters::HTMLLinewise

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

Instance Method Summary collapse

Methods inherited from Rouge::Formatter

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

Constructor Details

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

Returns a new instance of HTMLLinewise


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

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

Instance Method Details

#stream(tokens, &b) ⇒ Object


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

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