Module: Rabbit::Parser::RD::Ext::CharacterReference

Includes:
Element
Included in:
InlineVerbatim
Defined in:
lib/rabbit/parser/rd/ext/character-reference.rb

Constant Summary collapse

TABLE =
Parser::Ext::Entity::TABLE

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



12
13
14
15
16
# File 'lib/rabbit/parser/rd/ext/character-reference.rb', line 12

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

Instance Method Details

#ext_inline_verb_character_entity_reference(label, source, content, visitor) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rabbit/parser/rd/ext/character-reference.rb', line 20

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

#ext_inline_verb_numeric_character_reference(label, source, content, visitor) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rabbit/parser/rd/ext/character-reference.rb', line 35

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