Sha256: 475bb1d074ce22a0dd7424500c018dfc920987f23dfa94ebac0ecd6523850301

Contents?: true

Size: 669 Bytes

Versions: 5

Compression:

Stored size: 669 Bytes

Contents

module Asciidoctor
module Pdf
module FormattedText
class Formatter
  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
      warn %(Failed to parse formatted text: #{string})
      [text: string]
    end
  end
end
end
end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.5.0.alpha.16 lib/asciidoctor-pdf/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.15 lib/asciidoctor-pdf/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.14 lib/asciidoctor-pdf/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.13 lib/asciidoctor-pdf/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.12 lib/asciidoctor-pdf/formatted_text/formatter.rb