Sha256: ef4bbb5d89affc62ade49af73dc8c3e7ccf1b5337dde33a5a68f4d831a7c1cd4

Contents?: true

Size: 748 Bytes

Versions: 7

Compression:

Stored size: 748 Bytes

Contents

require 'treetop'
require 'set'
require_relative 'parser'
require_relative 'transform'

module Asciidoctor
module Prawn
class FormattedTextFormatter
  FormattingSnifferPattern = /[<&]/

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

  def format string, *args
    options = args.first || {}
    string = string.tr_s("\n", ' ') if options[:normalize]
    return [text: string] unless string.match(FormattingSnifferPattern)
    if (parsed = @parser.parse(string)) == nil
      warn %(Failed to parse formatted text: #{string})
      [text: string]
    else
      @transform.apply(parsed.content)
    end
  end
end
end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.5.0.alpha.7 lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.6 lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.5 lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.4 lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.3 lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.2 lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb
asciidoctor-pdf-1.5.0.alpha.1 lib/asciidoctor-pdf/prawn_ext/formatted_text/formatter.rb