Sha256: a2f54f4b0a37ce2b37d9a0ee40cd591b87a746b875ee0a961a1f4c5b7a5fe22f

Contents?: true

Size: 1.69 KB

Versions: 27

Compression:

Stored size: 1.69 KB

Contents

require 'rabbit/element'
require 'rabbit/parser/ext/entity'

module Rabbit
  module Parser
    class RD
      module Ext
        module CharacterReference
          include Element

          class << self
            def included(mod)
              self.instance_methods.each do |meth|
                mod.method_added(meth)
              end
            end
          end

          TABLE = Parser::Ext::Entity::TABLE
          def ext_inline_verb_character_entity_reference(label, source, content, visitor)
            label = label.to_s
            return nil unless /^&([^;]+);(.*)$/ =~ label
            return nil unless TABLE.include?($1)

            key = $1
            rest = $2
            if rest.empty?
              Text.new(TABLE[key])
            else
              rest = visitor.apply_to_Verb(::RD::Verb.new(rest))
              TextContainer.new([Text.new(TABLE[key]), rest])
            end
          end

          def ext_inline_verb_numeric_character_reference(label, source, content, visitor)
            label = label.to_s
            return nil unless /^&#(x?)([a-zA-Z\d]+);(.*)$/ =~ label

            base = $1
            unicode_code_point_string = $2
            rest = $3
            if base == "x"
              unicode_code_point = unicode_code_point_string.to_i(16)
            else
              unicode_code_point = unicode_code_point_string.to_i(10)
            end
            character = [unicode_code_point].pack("U")
            if rest.empty?
              Text.new(character)
            else
              rest = visitor.apply_to_Verb(::RD::Verb.new(rest))
              TextContainer.new([Text.new(character), rest])
            end
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rabbit-3.0.3 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-3.0.2 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-3.0.1 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-3.0.0 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.2.1 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.2.0 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.9 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.8 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.7 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.6 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.5 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.4 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.3 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.2 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.1 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.1.0 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.0.9 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.0.8 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.0.7 lib/rabbit/parser/rd/ext/character-reference.rb
rabbit-2.0.6 lib/rabbit/parser/rd/ext/character-reference.rb