Class: Asciidoctor::RougeExt::Formatters::HTMLTable
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Asciidoctor::RougeExt::Formatters::HTMLTable
- Defined in:
- lib/asciidoctor/rouge_ext.rb
Instance Method Summary collapse
-
#initialize(delegate, opts) ⇒ HTMLTable
constructor
A new instance of HTMLTable.
- #stream(tokens) {|%(<table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno">#{formatted_linenos}</pre></td><td class="code"><pre>#{formatted_code}</pre></td></tr></tbody></table>)| ... } ⇒ Object
Constructor Details
#initialize(delegate, opts) ⇒ HTMLTable
Returns a new instance of HTMLTable.
6 7 8 9 |
# File 'lib/asciidoctor/rouge_ext.rb', line 6 def initialize delegate, opts @delegate = delegate @start_line = opts[:start_line] || 1 end |
Instance Method Details
#stream(tokens) {|%(<table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno">#{formatted_linenos}</pre></td><td class="code"><pre>#{formatted_code}</pre></td></tr></tbody></table>)| ... } ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/asciidoctor/rouge_ext.rb', line 11 def stream tokens formatted_code = @delegate.format tokens formatted_code += LF unless formatted_code.end_with? LF, HangingEndSpanTagCs last_lineno = (first_lineno = @start_line) + (formatted_code.count LF) - 1 # assume number of newlines is constant lineno_format = %(%#{(::Math.log10 last_lineno).floor + 1}i) formatted_linenos = ((first_lineno..last_lineno).map {|lineno| sprintf lineno_format, lineno } << '').join LF yield %(<table class="linenotable"><tbody><tr><td class="linenos gl"><pre class="lineno">#{formatted_linenos}</pre></td><td class="code"><pre>#{formatted_code}</pre></td></tr></tbody></table>) end |