Class: Rouge::Formatters::HTMLLinewise
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Rouge::Formatters::HTMLLinewise
- Defined in:
- lib/rouge/formatters/html_linewise.rb
Constant Summary
Constants inherited from Rouge::Formatter
Instance Method Summary collapse
-
#initialize(formatter, opts = {}) ⇒ HTMLLinewise
constructor
A new instance of HTMLLinewise.
- #stream(tokens, &b) ⇒ 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(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 |
# File 'lib/rouge/formatters/html_linewise.rb', line 13 def stream(tokens, &b) token_lines(tokens).with_index(1) do |line_tokens, lineno| yield %(<#{@tag_name} class="#{sprintf @class_format, lineno}">) @formatter.stream(line_tokens) {|formatted| yield formatted } yield %(\n</#{@tag_name}>) end end |