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