Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/nori/parser/nokogiri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@ def start_element(name, attrs = [])
stack.push Nori::XMLUtilityNode.new(options, name, Hash[*attrs.flatten])
end

# To keep backward behaviour compatibility
# delete last child if it is a space-only text node
def end_element(name)
if stack.size > 1
last = stack.pop
maybe_string = last.children.last
if maybe_string.is_a?(String) and maybe_string.strip.empty?
last.children.pop
end
stack.last.add_node last
end
end

# If this node is a successive character then add it as is.
# First child being a space-only text node will not be added
# because there is no previous characters.
def characters(string)
stack.last.add_node(string) unless string.strip.length == 0 || stack.empty?
last = stack.last
if last and last.children.last.is_a?(String) or string.strip.size > 0
last.add_node(string)
end
end

alias cdata_block characters
Expand Down