Sha256: f84d273cc962bec849bdd768d32c6bc653049145723497dbd2db947a4fcf2aae
Contents?: true
Size: 883 Bytes
Versions: 4
Compression:
Stored size: 883 Bytes
Contents
# -*- coding: utf-8 -*- # # frozen_string_literal: true 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) return val if escape?(tok) 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 TABLE_FOR_ESCAPE_HTML = { '&' => '&', '<' => '<', '>' => '>', } end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rouge-3.5.1 | lib/rouge/formatters/html.rb |
rouge-3.5.0 | lib/rouge/formatters/html.rb |
rouge-3.4.1 | lib/rouge/formatters/html.rb |
rouge-3.4.0 | lib/rouge/formatters/html.rb |