Sha256: 7a085d4caf72ab7f87a6edb24cd29a0ad65579b7098f00ee6591c96ba7d5434a
Contents?: true
Size: 845 Bytes
Versions: 19
Compression:
Stored size: 845 Bytes
Contents
module Nokogiri module XML class BeforeHandler < Nokogiri::XML::SAX::Document # :nodoc: def initialize node, original_html @original_html = original_html @node = node @document = node.document @stack = [] end def start_element name, attrs = [] return unless @original_html =~ /<#{name}/i node = Node.new(name, @document) Hash[*attrs].each do |k,v| node[k] = v end node.parent = @stack.last if @stack.length != 0 @stack << node end def characters string node = @stack.last node.content += string end def end_element name return unless @original_html =~ /<#{name}/i @node.add_previous_sibling @stack.last if @stack.length == 1 @stack.pop end end end end
Version data entries
19 entries across 19 versions & 1 rubygems