Sha256: 63c22a395ca6167c4fbbd504a17fa91dad73f41e05a384f9d0d7470291cf38a8

Contents?: true

Size: 605 Bytes

Versions: 4

Compression:

Stored size: 605 Bytes

Contents

module ImproveTypography
  module Processors
    class Nbsp < Processor
      def call
        return str unless str.match?(/(\A|\s+)(\S|\d+)([\.?!]?)(\s+|\z)/)

        str
          .gsub(/(\s+)(\S|\d+|\S\.)(\s+)(\S)/, '\1\2&nbsp;\4') # in the middle of string
          .gsub(/\A(\w|\d+|\w\.)(\s+)(\S)/, '\1&nbsp;\3') # at the beginning of string
          .gsub(/([^\S\n])(\S|\d+|\S\.)(\z|[\.?!]\z|[\.?!]\s)/, '&nbsp;\2\3') # at the end of string!!
          .gsub(/(\A|\s+)(©)(\s+)(\d+)/, '\1\2&nbsp;\4')
          .gsub(/(\A|\s+)(No\.|Vol\.)(\s+)(\d+)/, '\1\2&nbsp;\3')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
improve_typography-0.1.17 lib/improve_typography/processors/nbsp.rb
improve_typography-0.1.16 lib/improve_typography/processors/nbsp.rb
improve_typography-0.1.15 lib/improve_typography/processors/nbsp.rb
improve_typography-0.1.14 lib/improve_typography/processors/nbsp.rb