public static String getPlainHtml(Element element) { FormattingVisitor formatter = new FormattingVisitor(); NodeTraversor traversor = new NodeTraversor(formatter); traversor.traverse(element); // walk the DOM, and call .head() and .tail() for each node return formatter.toString(); }
/** * @param htmlText * @return */ public static String htmlToPlainText(String htmlText) { // replace the blanks in previous htmlText = htmlText.replaceAll(" ", ""); Document doc = Jsoup.parse(htmlText); FormattingVisitor formatter = new FormattingVisitor(); NodeTraversor traversor = new NodeTraversor(formatter); traversor.traverse(doc); return formatter.toString().trim(); }
private int copySafeNodes(Element source, Element dest) { CleaningVisitor cleaningVisitor = new CleaningVisitor(source, dest); NodeTraversor traversor = new NodeTraversor(cleaningVisitor); traversor.traverse(source); return cleaningVisitor.numDiscarded; }
public static String getPlainText(Element element) { PlainTextFormatter plainTextFormatter = new PlainTextFormatter(); NodeTraversor traversor = new NodeTraversor(plainTextFormatter); traversor.traverse(element); return plainTextFormatter.toString(); }