A Formatter takes a token stream and formats it for human viewing.
@private
Find a formatter class given a unique tag.
# File lib/rouge/formatter.rb, line 18 def self.find(tag) REGISTRY[tag] end
Format a token stream. Delegates to {#format}.
# File lib/rouge/formatter.rb, line 23 def self.format(tokens, opts={}, &b) new(opts).format(tokens, &b) end
Specify or get the unique tag for this formatter. This is used for specifying a formatter in `rougify`.
# File lib/rouge/formatter.rb, line 10 def self.tag(tag=nil) return @tag unless tag REGISTRY[tag] = self @tag = tag end
Format a token stream.
# File lib/rouge/formatter.rb, line 28 def format(tokens, &b) return stream(tokens, &b) if block_given? out = '' stream(tokens) { |piece| out << piece } out end
@deprecated Use {#format} instead.
# File lib/rouge/formatter.rb, line 38 def render(tokens) warn 'Formatter#render is deprecated, use #format instead.' format(tokens) end
@abstract yield strings that, when concatenated, form the formatted output
# File lib/rouge/formatter.rb, line 45 def stream(tokens, &b) raise 'abstract' end