Class: Rouge::Formatters::HTMLLineTable
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Rouge::Formatters::HTMLLineTable
- Defined in:
- lib/rouge/formatters/html_line_table.rb
Instance Method Summary collapse
-
#initialize(formatter, opts = {}) ⇒ HTMLLineTable
constructor
A new instance of HTMLLineTable.
- #stream(tokens) {|buffer.join| ... } ⇒ Object
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 = {}) ⇒ HTMLLineTable
Returns a new instance of HTMLLineTable.
24 25 26 27 28 29 30 31 32 |
# File 'lib/rouge/formatters/html_line_table.rb', line 24 def initialize(formatter, opts={}) @formatter = formatter @start_line = opts.fetch :start_line, 1 @table_class = opts.fetch :table_class, 'rouge-line-table' @gutter_class = opts.fetch :gutter_class, 'rouge-gutter' @code_class = opts.fetch :code_class, 'rouge-code' @line_class = opts.fetch :line_class, 'lineno' @line_id = opts.fetch :line_id, 'line-%i' end |
Instance Method Details
#stream(tokens) {|buffer.join| ... } ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rouge/formatters/html_line_table.rb', line 34 def stream(tokens, &b) buffer = [%(<table class="#@table_class"><tbody>)] token_lines(tokens).with_index(@start_line) do |line_tokens, lineno| buffer << %(<tr id="#{sprintf @line_id, lineno}" class="#@line_class">) buffer << %(<td class="#@gutter_class gl" ) buffer << %(style="-moz-user-select: none;-ms-user-select: none;) buffer << %(-webkit-user-select: none;user-select: none;">) buffer << %(<pre>#{lineno}</pre></td>) buffer << %(<td class="#@code_class"><pre>) @formatter.stream(line_tokens) { |formatted| buffer << formatted } buffer << "\n</pre></td></tr>" end buffer << %(</tbody></table>) yield buffer.join end |