Class: Rouge::Formatters::HTML
Overview
Transforms a token stream into HTML output.
Constant Summary
collapse
- TABLE_FOR_ESCAPE_HTML =
{
'&' => '&',
'<' => '<',
'>' => '>',
"\r" => "",
}.freeze
- ESCAPE_REGEX =
/[&<>\r]/.freeze
Rouge::Formatter::REGISTRY
Class Method Summary
collapse
Instance Method Summary
collapse
disable_escape!, enable_escape!, #escape?, escape_enabled?, #filter_escapes, find, format, #format, #initialize, #render, tag, with_escape
Class Method Details
17
18
19
20
21
|
# File 'lib/rouge/formatters/html.rb', line 17
def self.assert_html_formatter!(formatter)
return formatter if formatter.respond_to?(:span)
raise ArgumentError.new("Expected an instance of Rouge::Formatters::HTML, got #{formatter.class}. Try HTML, HTMLDebug, or HTMLInline.")
end
|
Instance Method Details
#safe_span(tok, safe_val) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/rouge/formatters/html.rb', line 36
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
30
31
32
33
34
|
# File 'lib/rouge/formatters/html.rb', line 30
def span(tok, val)
return val if escape?(tok)
safe_span(tok, escape_special_html_chars(val))
end
|
#stream(tokens) { ... } ⇒ Object
26
27
28
|
# File 'lib/rouge/formatters/html.rb', line 26
def stream(tokens, &b)
tokens.each { |tok, val| yield span(tok, val) }
end
|