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, '%i')
end

Instance Method Details

#next_line_classObject



25
26
27
28
# File 'lib/rouge/formatters/html_linewise.rb', line 25

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

#stream(tokens) {|"<span class=#{next_line_class}>"| ... } ⇒ Object

Yields:



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

def stream(tokens, &b)
  yield "<span class=#{next_line_class}>"
  tokens.each do |tok, val|
    val.scan /\n|[^\n]+/ do |s|
      if s == "\n"
        yield "</span>\n<span class=#{next_line_class}>"
      else
        @formatter.span(tok, s)
      end
    end
  end
  yield "</span>"
end