Class: Rouge::Formatters::HTML
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Rouge::Formatters::HTML
- Defined in:
- lib/rouge/formatters/html.rb
Overview
Transforms a token stream into HTML output.
Constant Summary
Constants inherited from Rouge::Formatter
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ HTML
constructor
A css class to be used for the generated <pre> tag.
- #stream(tokens) { ... } ⇒ Object
Methods inherited from Rouge::Formatter
find, format, #format, #render, tag
Constructor Details
#initialize(opts = {}) ⇒ HTML
A css class to be used for the generated <pre> tag.
12 13 14 |
# File 'lib/rouge/formatters/html.rb', line 12 def initialize(opts={}) @css_class = opts[:css_class] || 'highlight' end |
Instance Method Details
#stream(tokens) { ... } ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rouge/formatters/html.rb', line 17 def stream(tokens, &b) yield "<pre class=#{@css_class.inspect}>" tokens.each do |tok, val| # TODO: properly html-encode val val = CGI.escape_html(val) case tok.shortname when '' yield val when nil raise "unknown token: #{tok.inspect}" else yield '<span class=' yield tok.shortname.inspect yield '>' yield val yield '</span>' end end yield '</pre>' end |