class Asciidoctor::Pdf::FormattedText::Formatter

Constants

EOL
FormattingSnifferPattern

Public Class Methods

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

Public Instance Methods

format(string, *args) click to toggle source
# File lib/asciidoctor-pdf/formatted_text/formatter.rb, line 13
def format string, *args
  options = args[0] || {}
  string = string.tr_s(EOL, ' ') if options[:normalize]
  return [text: string] unless string.match(FormattingSnifferPattern)
  if (parsed = @parser.parse(string))
    @transform.apply(parsed.content)
  else
    warn %Q(Failed to parse formatted text: #{string})
    [text: string]
  end
end