class Rouge::Formatter
A Formatter takes a token stream and formats it for human viewing.
def self.find(tag)
def self.find(tag) REGISTRY[tag] end
def self.format(tokens, opts={}, &b)
def self.format(tokens, opts={}, &b) new(opts).format(tokens, &b) end
def self.tag(tag=nil)
Specify or get the unique tag for this formatter. This is used
def self.tag(tag=nil) return @tag unless tag REGISTRY[tag] = self @tag = tag end
def format(tokens, &b)
def format(tokens, &b) return stream(tokens, &b) if block_given? out = '' stream(tokens) { |piece| out << piece } out end
def initialize(opts={})
def initialize(opts={}) # pass end
def render(tokens)
- Use {#format} instead.
def render(tokens) warn 'Formatter#render is deprecated, use #format instead.' format(tokens) end
def stream(tokens, &b)
- Abstract: -
def stream(tokens, &b) raise 'abstract' end
def token_lines(tokens, &b)
def token_lines(tokens, &b) return enum_for(:token_lines, tokens) unless block_given? out = [] tokens.each do |tok, val| val.scan /\n|[^\n]+/ do |s| if s == "\n" yield out out = [] else out << [tok, s] end end end # for inputs not ending in a newline yield out if out.any? end