Given an HTML document in Nokogiri, I want to remove all <p> nodes with no actual text. This includes <p> elements with whitespace and/or <br/> tags. What’s the most elegant way to do this?
Given an HTML document in Nokogiri, I want to remove all <p> nodes with
Share
I would start with a method like this one (feel free to monkeypatch
Nokogiri::XML::Nodeif you want to)Then continue with another method that checks that all children are blank:
And finally, get the
documentand