Sha256: 837685b7d25d69c00867358f543305a02754376592ba2ac90406c66dd60e18d7

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

Contents

module Asciidoctor
module PDF
module FormattedText
class Formatter
  if defined? ::Asciidoctor::Logging
    include ::Asciidoctor::Logging
  else
    include ::Asciidoctor::LoggingShim
  end

  FormattingSnifferPattern = /[<&]/
  WHITESPACE = " \t\n"

  def initialize options = {}
    @parser = MarkupParser.new
    @transform = Transform.new merge_adjacent_text_nodes: true, theme: options[:theme]
  end

  def format string, *args
    options = args[0] || {}
    string = string.tr_s(WHITESPACE, ' ') if options[:normalize]
    return [text: string] unless string.match(FormattingSnifferPattern)
    if (parsed = @parser.parse(string))
      @transform.apply(parsed.content)
    else
      logger.error %(failed to parse formatted text: #{string})
      [text: string]
    end
  end
end
end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.5.0.alpha.17 lib/asciidoctor-pdf/formatted_text/formatter.rb