Class: Rouge::Formatters::HTML
- Inherits:
-
Rouge::Formatter
- Object
- Rouge::Formatter
- Rouge::Formatters::HTML
- Defined in:
- lib/rouge/formatters/html.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ HTML
constructor
A new instance of HTML.
- #stream(tokens) {|"<pre class=#{@css_class.inspect}>"| ... } ⇒ Object
Methods inherited from Rouge::Formatter
Constructor Details
#initialize(opts = {}) ⇒ HTML
Returns a new instance of HTML.
7 8 9 |
# File 'lib/rouge/formatters/html.rb', line 7 def initialize(opts={}) @css_class = opts[:css_class] || 'highlight' end |
Instance Method Details
#stream(tokens) {|"<pre class=#{@css_class.inspect}>"| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rouge/formatters/html.rb', line 11 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 |