Class: Rouge::Formatters::HTMLLineHighlighter

Inherits:
Rouge::Formatter show all
Defined in:
lib/rouge/formatters/html_line_highlighter.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(delegate, opts = {}) ⇒ HTMLLineHighlighter

Returns a new instance of HTMLLineHighlighter.



9
10
11
12
13
# File 'lib/rouge/formatters/html_line_highlighter.rb', line 9

def initialize(delegate, opts = {})
  @delegate = delegate
  @highlight_line_class = opts.fetch(:highlight_line_class, 'hll')
  @highlight_lines = opts[:highlight_lines] || []
end

Instance Method Details

#stream(tokens) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rouge/formatters/html_line_highlighter.rb', line 15

def stream(tokens)
  token_lines(tokens).with_index(1) do |line_tokens, lineno|
    line = %(#{@delegate.format(line_tokens)}\n)
    line = %(<span class="#{@highlight_line_class}">#{line}</span>) if @highlight_lines.include? lineno
    yield line
  end
end