Sha256: 5e9b22e94f57ad918b53a6db7e9b9f149d2523c75d3da80c839873b79f8499ab

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

# -*- coding: utf-8; frozen_string_literal: true -*-
#
#--
# Copyright (C) 2009-2019 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'
      path = $:.find do |dir|
        File.directory?(File.join(File.expand_path(dir), "stringex", "unidecoder_data"))
      end

      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[sprintf("x%02x", unpacked >> 8)][unpacked & 255]
            rescue StandardError
              "?"
            end
          end
        end

      end

    end

  end
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/kramdown-2.4.0/lib/kramdown/utils/unidecoder.rb
kramdown-2.4.0 lib/kramdown/utils/unidecoder.rb
kramdown-2.3.2 lib/kramdown/utils/unidecoder.rb
kramdown-2.3.1 lib/kramdown/utils/unidecoder.rb
daqing_kramdown-2.3.2 lib/kramdown/utils/unidecoder.rb
daqing_kramdown-2.3.1 lib/kramdown/utils/unidecoder.rb
zine_brewer-1.5.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/utils/unidecoder.rb
zine_brewer-1.3.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/utils/unidecoder.rb
kramdown-2.3.0 lib/kramdown/utils/unidecoder.rb
kramdown-2.2.1 lib/kramdown/utils/unidecoder.rb
kramdown-2.2.0 lib/kramdown/utils/unidecoder.rb
kramdown-2.1.0 lib/kramdown/utils/unidecoder.rb
kramdown-2.0.0 lib/kramdown/utils/unidecoder.rb
kramdown-2.0.0.beta2 lib/kramdown/utils/unidecoder.rb
kramdown-2.0.0.beta1 lib/kramdown/utils/unidecoder.rb