Class: TTY::Markdown::Formatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/markdown/formatter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for formatting code snippets with standard terminal colors

Instance Method Summary collapse

Constructor Details

#initialize(decorator) ⇒ Formatter

Create a TTY::Markdown::Formatter instance

Examples:

formatter = TTY::Markdown::Formatter.new(decorator)

Parameters:



18
19
20
# File 'lib/tty/markdown/formatter.rb', line 18

def initialize(decorator)
  @decorator = decorator
end

Instance Method Details

#format(tokens) ⇒ String

Format the Rouge lexer tokens

Examples:

formatter.format(tokens)

Parameters:

  • tokens (Enumerator)

    the Rouge lexer tokens

Returns:

  • (String)


33
34
35
36
# File 'lib/tty/markdown/formatter.rb', line 33

def format(tokens)
  code = tokens.map { |_token, value| value }.join
  @decorator.decorate_each_line(code, :code)
end