Class: Rouge::Formatters::HTMLLineHighlighter
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Rouge::Formatters::HTMLLineHighlighter
- Defined in:
- lib/rouge/formatters/html_line_highlighter.rb
Constant Summary
Constants inherited from Rouge::Formatter
Instance Method Summary collapse
-
#initialize(delegate, opts = {}) ⇒ HTMLLineHighlighter
constructor
A new instance of HTMLLineHighlighter.
- #stream(tokens) ⇒ Object
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.
14 15 16 17 18 |
# File 'lib/rouge/formatters/html_line_highlighter.rb', line 14 def initialize(delegate, opts = {}) @delegate = HTML.assert_html_formatter!(delegate) @highlight_line_class = opts.fetch(:highlight_line_class, 'hll') @highlight_lines = opts[:highlight_lines] || [] end |
Instance Method Details
#stream(tokens) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rouge/formatters/html_line_highlighter.rb', line 20 def stream(tokens) token_lines(tokens).with_index(1) do |line_tokens, lineno| should_highlight = @highlight_lines.include?(lineno) yield %(<span class=#{@highlight_line_class.inspect}>) if should_highlight line_tokens.each { |tok, val| yield @delegate.span(tok, val) } yield "\n" yield %(</span>) if should_highlight end end |