Sha256: 8f69dc5df3476fa2ceca041f594b3aa12b8a1d7b2be8779ff2192ce41367dd34

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2016 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown which is licensed under the MIT.
#++
#
# This file is based on code originally from the Stringex library and needs the data files from
# Stringex to work correctly.

module Kramdown
  module Utils

    # Provides the ability to tranliterate Unicode strings into plain ASCII ones.
    module Unidecoder

      gem 'stringex' if defined?(Gem)
      path = $:.find {|dir| File.directory?(File.join(File.expand_path(dir), "stringex", "unidecoder_data"))}

      if !path
        def self.decode(string)
          string
        end
      else

        CODEPOINTS = Hash.new do |h, k|
          h[k] = YAML.load_file(File.join(path, "stringex", "unidecoder_data", "#{k}.yml"))
        end

        # Transliterate string from Unicode into ASCII.
        def self.decode(string)
          string.gsub(/[^\x00-\x7f]/u) do |codepoint|
            begin
              unpacked = codepoint.unpack("U")[0]
              CODEPOINTS["x%02x" % (unpacked >> 8)][unpacked & 255]
            rescue
              "?"
            end
          end
        end

      end

    end

  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/kramdown-1.17.0/lib/kramdown/utils/unidecoder.rb
kramdown-1.17.0 lib/kramdown/utils/unidecoder.rb
kramdown-1.16.2 lib/kramdown/utils/unidecoder.rb
kramdown-1.16.1 lib/kramdown/utils/unidecoder.rb
kramdown-1.16.0 lib/kramdown/utils/unidecoder.rb
kramdown-1.15.0 lib/kramdown/utils/unidecoder.rb