Created
February 22, 2017 18:53
-
-
Save EdgeCaseBerg/50c5d4242328516ebe26ff4fb55d14ab to your computer and use it in GitHub Desktop.
Revisions
-
EdgeCaseBerg created this gist
Feb 22, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ import org.jsoup.Jsoup import org.jsoup.nodes.Document import scala.collection.JavaConverters._ def removeAllEmptyChildren(doc: Document): = { val allElements = doc.body().getAllElements() allElements.asScala.foreach { element => if(!element.hasText) { element.remove() } } doc } /* scala> Jsoup.parse("<p>hi there</p><p><b>Bold text</b><i></i><p></p> yay stuff and things</p>") res0: org.jsoup.nodes.Document = <html> <head></head> <body> <p>hi there</p> <p><b>Bold text</b><i></i></p> <p></p> yay stuff and things <p></p> </body> </html> scala> removeAllEmptyChildren(res0) res1: org.jsoup.nodes.Document = <html> <head></head> <body> <p>hi there</p> <p><b>Bold text</b></p> yay stuff and things </body> </html> */