class Asciidoctor::RougeExt::Formatters::HTMLTable

Public Class Methods

new(delegate, opts) click to toggle source
# File lib/asciidoctor/rouge_ext.rb, line 6
def initialize delegate, opts
  @delegate = delegate
  @start_line = opts[:start_line] || 1
end

Public Instance Methods

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>)| ... } click to toggle source
# 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