Method: CodeRay::Encoders::XML#text_token

Defined in:
lib/coderay/encoders/xml.rb

#text_token(text, kind) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/coderay/encoders/xml.rb', line 38

def text_token text, kind
  if kind == :space
    token = @node
  else
    token = @node.add_element kind.to_s
  end
  text.scan(/(\x20+)|(\t+)|(\n)|[^\x20\t\n]+/) do |space, tab, nl|
    case
    when space
      token << REXML::Text.new(space, true)
    when tab
      token << REXML::Text.new(tab, true)
    when nl
      token << REXML::Text.new(nl, true)
    else
      token << REXML::Text.new($&)
    end
  end
end