This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'oga' | |
document = Oga.parse_html <<-EOF | |
<div>this should</div> | |
<span>really go</span> | |
<b>away</b> | |
<h1>First Title</h1> | |
Hello world, how are you <b>doing?</b> | |
EOF | |
document.each_node do |node| | |
if node.is_a?(Oga::XML::Element) and node.name == 'h1' | |
break | |
else | |
node.remove | |
end | |
end | |
document.xpath('descendant-or-self::b').each do |b_node| | |
text = Oga::XML::Text.new(:text => "**#{b_node.inner_text}**") | |
b_node.before(text) | |
b_node.remove | |
end | |
puts document.to_xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment