Class: Rouge::Formatters::HTML

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

Overview

Transforms a token stream into HTML output.

Direct Known Subclasses

HTMLInline

Constant Summary

Constants inherited from Rouge::Formatter

Rouge::Formatter::REGISTRY

Instance Method Summary collapse

Methods inherited from Rouge::Formatter

find, format, #format, #initialize, #render, tag

Constructor Details

This class inherits a constructor from Rouge::Formatter

Instance Method Details

#safe_span(tok, safe_val) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/rouge/formatters/html.rb', line 18

def safe_span(tok, safe_val)
  if tok == Token::Tokens::Text
    safe_val
  else
    shortname = tok.shortname \
      or raise "unknown token: #{tok.inspect} for #{safe_val.inspect}"

    "<span class=\"#{shortname}\">#{safe_val}</span>"
  end
end

#span(tok, val) ⇒ Object



14
15
16
# File 'lib/rouge/formatters/html.rb', line 14

def span(tok, val)
  safe_span(tok, val.gsub(/[&<>]/, TABLE_FOR_ESCAPE_HTML))
end

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

Yields:

  • the html output.



10
11
12
# File 'lib/rouge/formatters/html.rb', line 10

def stream(tokens, &b)
  tokens.each { |tok, val| yield span(tok, val) }
end