class Asciidoctor::PDF::FormattedText::Formatter

Constants

FormattingSnifferPattern
WHITESPACE

Public Class Methods

new(options = {}) click to toggle source
# File lib/asciidoctor-pdf/formatted_text/formatter.rb, line 14
def initialize options = {}
  @parser = MarkupParser.new
  @transform = Transform.new merge_adjacent_text_nodes: true, theme: options[:theme]
end

Public Instance Methods

array_paragraphs(fragments) click to toggle source

The original purpose of this method is to split paragraphs, but our formatter only works on paragraphs that have been presplit. Therefore, we just need to wrap the fragments in a single-element array (representing a single paragraph) and return them.

# File lib/asciidoctor-pdf/formatted_text/formatter.rb, line 34
def array_paragraphs fragments
  [fragments]
end
format(string, *args) click to toggle source
# File lib/asciidoctor-pdf/formatted_text/formatter.rb, line 19
def format string, *args
  options = args[0] || {}
  string = string.tr_s(WHITESPACE, ' ') if options[:normalize]
  return [text: string] unless FormattingSnifferPattern.match? string
  if (parsed = @parser.parse(string))
    @transform.apply(parsed.content)
  else
    logger.error %(failed to parse formatted text: #{string})
    [text: string]
  end
end