Class: Rouge::Formatters::BHTML

Inherits:
Formatter
  • Object
show all
Defined in:
lib/burr/rouge_ext/html_formatter.rb

Overview

Transforms a token stream into HTML output.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BHTML

Initialize with options.

If ‘:inline_theme` is given, then instead of rendering the tokens as <span> tags with CSS classes, the styles according to the given theme will be inlined in “style” attributes. This is useful for formats in which stylesheets are not available.

Content will be wrapped in a tag with the given ‘:css_class` unless `:wrap` is set to `false`.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :css_class (String) — default: 'highlight'
  • :line_numbers (true/false) — default: false
  • :inline_theme (Rouge::CSSTheme) — default: nil
  • :wrap (true/false) — default: true


24
25
26
27
28
29
# File 'lib/burr/rouge_ext/html_formatter.rb', line 24

def initialize(opts={})
  @css_class = opts.fetch(:css_class, 'highlight')
  @line_numbers = opts.fetch(:line_numbers, false)
  @inline_theme = opts.fetch(:inline_theme, nil)
  @wrap = opts.fetch(:wrap, true)
end

Instance Method Details

#stream(tokens) { ... } ⇒ Object

Yields:

  • the html output.



32
33
34
35
36
37
38
# File 'lib/burr/rouge_ext/html_formatter.rb', line 32

def stream(tokens, &b)
  if @line_numbers
    stream_tableized(tokens, &b)
  else
    stream_untableized(tokens, &b)
  end
end