class Rouge::Formatter

A Formatter takes a token stream and formats it for human viewing.

def self.disable_escape!

def self.disable_escape!
  @escape_enabled = false
  Thread.current[:'rouge/with-escape'] = false
end

def self.enable_escape!

def self.enable_escape!
  @escape_enabled = true
end

def self.escape_enabled?

def self.escape_enabled?
  !!(((defined? @escape_enabled) && @escape_enabled) || Thread.current[:'rouge/with-escape'])
end

def self.find(tag)

Find a formatter class given a unique tag.
def self.find(tag)
  REGISTRY[tag]
end

def self.format(tokens, *args, **kwargs, &b)

Format a token stream. Delegates to {#format}.
def self.format(tokens, *args, **kwargs, &b)
  new(*args, **kwargs).format(tokens, &b)
end

def self.tag(tag=nil)

for specifying a formatter in `rougify`.
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 self.with_escape

def self.with_escape
  Thread.current[:'rouge/with-escape'] = true
  yield
ensure
  Thread.current[:'rouge/with-escape'] = false
end

def escape?(tok)

def escape?(tok)
  tok == Token::Tokens::Escape
end

def filter_escapes(tokens)

def filter_escapes(tokens)
  tokens.each do |t, v|
    if t == Token::Tokens::Escape
      yield Token::Tokens::Error, v
    else
      yield t, v
    end
  end
end

def format(tokens, &b)

Format a token stream.
def format(tokens, &b)
  tokens = enum_for(:filter_escapes, tokens) unless Formatter.escape_enabled?
  return stream(tokens, &b) if block_given?
  out = String.new('')
  stream(tokens) { |piece| out << piece }
  out
end

def initialize(opts={})

def initialize(opts={})
  # pass
end

def render(tokens)

Deprecated:
  • Use {#format} instead.
def render(tokens)
  warn 'Formatter#render is deprecated, use #format instead.'
  format(tokens)
end

def stream(tokens, &b)

Other tags:
    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 %r/\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