Sha256: acb209ebba0a0f4830c3c6baab9c9cca14dee73aa10988b8764a958df27112a0

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Asciidoctor
  module PDF
    module TextTransformer
      XMLMarkupRx = /&#?[a-z\d]+;|</
      PCDATAFilterRx = /(&#?[a-z\d]+;|<[^>]+>)|([^&<]+)/
      TagFilterRx = /(<[^>]+>)|([^<]+)/
      ContiguousCharsRx = /\p{Graph}+/
      WordRx = /\p{Word}+/
      Hyphen = '-'
      SoftHyphen = ?\u00ad

      def capitalize_words_pcdata string
        if XMLMarkupRx.match? string
          string.gsub(PCDATAFilterRx) { $2 ? (capitalize_words $2) : $1 }
        else
          capitalize_words string
        end
      end

      def capitalize_words string
        string.gsub(ContiguousCharsRx) { $&.capitalize }
      end

      def hyphenate_words_pcdata string, hyphenator
        if XMLMarkupRx.match? string
          string.gsub(PCDATAFilterRx) { $2 ? (hyphenate_words $2, hyphenator) : $1 }
        else
          hyphenate_words string, hyphenator
        end
      end

      def hyphenate_words string, hyphenator
        string.gsub(WordRx) { hyphenator.visualize $&, SoftHyphen }
      end

      def lowercase_pcdata string
        if string.include? '<'
          string.gsub(TagFilterRx) { $2 ? $2.downcase : $1 }
        else
          string.downcase
        end
      end

      def uppercase_pcdata string
        if XMLMarkupRx.match? string
          string.gsub(PCDATAFilterRx) { $2 ? $2.upcase : $1 }
        else
          string.upcase
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.0.0.alpha.3 lib/asciidoctor/pdf/text_transformer.rb
asciidoctor-pdf-2.0.0.alpha.2 lib/asciidoctor/pdf/text_transformer.rb
asciidoctor-pdf-2.0.0.alpha.1 lib/asciidoctor/pdf/text_transformer.rb
asciidoctor-pdf-1.6.2 lib/asciidoctor/pdf/text_transformer.rb
asciidoctor-pdf-1.6.1 lib/asciidoctor/pdf/text_transformer.rb
asciidoctor-pdf-1.6.0 lib/asciidoctor/pdf/text_transformer.rb