Method: HTree::Text.parse_pcdata

Defined in:
lib/htree/parse.rb

.parse_pcdata(raw_string) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/htree/parse.rb', line 305

def Text.parse_pcdata(raw_string)
  fixed = raw_string.gsub(/&(?:(?:#[0-9]+|#x[0-9a-fA-F]+|([A-Za-z][A-Za-z0-9]*));?)?/o) {|s|
    name = $1
    case s
    when /;\z/
      s
    when /\A&#/
      "#{s};"
    when '&'
      '&'
    else 
      if NamedCharactersPattern =~ name
        "&#{name};"
      else
        "&#{name}"
      end
    end
  }
  fixed = raw_string if fixed == raw_string
  result = Text.new_internal(fixed)
  result.raw_string = raw_string
  result
end