Sha256: 395c2b0ee798be0882cc9138aeddaf1412c59e621ff689a4d6c4df405d10eeb2

Contents?: true

Size: 747 Bytes

Versions: 11

Compression:

Stored size: 747 Bytes

Contents

# stdlib
require 'cgi'

module Rouge
  module Formatters
    class HTML < Formatter
      def initialize(opts={})
        @css_class = opts[:css_class] || 'highlight'
      end

      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
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rouge-0.0.13 lib/rouge/formatters/html.rb
rouge-0.0.12 lib/rouge/formatters/html.rb
rouge-0.0.11 lib/rouge/formatters/html.rb
rouge-0.0.10 lib/rouge/formatters/html.rb
rouge-0.0.9 lib/rouge/formatters/html.rb
rouge-0.0.8 lib/rouge/formatters/html.rb
rouge-0.0.7 lib/rouge/formatters/html.rb
rouge-0.0.6 lib/rouge/formatters/html.rb
rouge-0.0.5 lib/rouge/formatters/html.rb
rouge-0.0.4 lib/rouge/formatters/html.rb
rouge-0.0.3 lib/rouge/formatters/html.rb