예제 #1
0
  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();
  }
예제 #2
0
  /**
   * @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();
  }
예제 #3
0
 private int copySafeNodes(Element source, Element dest) {
   CleaningVisitor cleaningVisitor = new CleaningVisitor(source, dest);
   NodeTraversor traversor = new NodeTraversor(cleaningVisitor);
   traversor.traverse(source);
   return cleaningVisitor.numDiscarded;
 }
예제 #4
0
 public static String getPlainText(Element element) {
   PlainTextFormatter plainTextFormatter = new PlainTextFormatter();
   NodeTraversor traversor = new NodeTraversor(plainTextFormatter);
   traversor.traverse(element);
   return plainTextFormatter.toString();
 }