Class: Rouge::Formatters::HTMLLegacy

Inherits:
Rouge::Formatter show all
Defined in:
lib/rouge/formatters/html_legacy.rb

Overview

Transforms a token stream into HTML output.

Constant Summary

Constants inherited from Rouge::Formatter

Rouge::Formatter::REGISTRY

Instance Method Summary collapse

Methods inherited from Rouge::Formatter

disable_escape!, enable_escape!, #escape?, escape_enabled?, #filter_escapes, find, format, #format, #render, tag, with_escape

Constructor Details

#initialize(opts = {}) ⇒ HTMLLegacy

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 (‘div` if tableized, `pre` if not) 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


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rouge/formatters/html_legacy.rb', line 29

def initialize(opts={})
  warn '[DEPRECATED] Rouge::Formatters::HTMLLegacy is deprecated and will be removed soon. Please use one of the other formatters, or write your own.'
  @formatter = opts[:inline_theme] ? HTMLInline.new(opts[:inline_theme])
             : HTML.new


  @formatter = HTMLTable.new(@formatter, opts) if opts[:line_numbers]

  if opts.fetch(:wrap, true)
    @pygments_wrap = opts.fetch(:css_class, 'codehilite')
  end
end

Instance Method Details

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

Yields:

  • the html output.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rouge/formatters/html_legacy.rb', line 43

def stream(tokens, &b)
  if @pygments_wrap
    yield %(<div class="highlight"><pre class="#{@pygments_wrap}"><code>)
  end

  @formatter.stream(tokens, &b)

  if @pygments_wrap
    yield "</code></pre></div>"
  end
end