Sha256: e20fd54e9594c30dbd6f5d6054687a7ca72f129ed3d72c7846bbb7b6603be988
Contents?: true
Size: 828 Bytes
Versions: 9
Compression:
Stored size: 828 Bytes
Contents
# -*- coding: utf-8 -*- # module Rouge module Formatters # Transforms a token stream into HTML output. class HTML < Formatter tag 'html' # @yield the html output. def stream(tokens, &b) tokens.each { |tok, val| yield span(tok, val) } end def span(tok, val) safe_span(tok, val.gsub(/[&<>]/, TABLE_FOR_ESCAPE_HTML)) end 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 private TABLE_FOR_ESCAPE_HTML = { '&' => '&', '<' => '<', '>' => '>', } end end end
Version data entries
9 entries across 8 versions & 2 rubygems