use of org.jsoup.select.NodeTraversor in project jsoup by jhy.
the class Cleaner method copySafeNodes.
private int copySafeNodes(Element source, Element dest) {
CleaningVisitor cleaningVisitor = new CleaningVisitor(source, dest);
NodeTraversor traversor = new NodeTraversor(cleaningVisitor);
traversor.traverse(source);
return cleaningVisitor.numDiscarded;
}
use of org.jsoup.select.NodeTraversor in project jsoup by jhy.
the class Node method traverse.
/**
* Perform a depth-first traversal through this node and its descendants.
* @param nodeVisitor the visitor callbacks to perform on each node
* @return this node, for chaining
*/
public Node traverse(NodeVisitor nodeVisitor) {
Validate.notNull(nodeVisitor);
NodeTraversor traversor = new NodeTraversor(nodeVisitor);
traversor.traverse(this);
return this;
}
use of org.jsoup.select.NodeTraversor in project jsoup by jhy.
the class HtmlToPlainText method getPlainText.
/**
* Format an Element to plain-text
* @param element the root element to format
* @return formatted text
*/
public String getPlainText(Element element) {
FormattingVisitor formatter = new FormattingVisitor();
NodeTraversor traversor = new NodeTraversor(formatter);
// walk the DOM, and call .head() and .tail() for each node
traversor.traverse(element);
return formatter.toString();
}
use of org.jsoup.select.NodeTraversor in project flow by vaadin.
the class TemplateParser method collectIncludeNodes.
private static List<TextNode> collectIncludeNodes(Element element) {
List<TextNode> includeNodes = new ArrayList<>();
new NodeTraversor(new NodeVisitor() {
@Override
public void head(Node node, int depth) {
// nop
}
@Override
public void tail(Node node, int depth) {
if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
String text = textNode.getWholeText();
if (text.contains(INCLUDE_PREFIX)) {
includeNodes.add(textNode);
}
}
}
}).traverse(element);
return includeNodes;
}
use of org.jsoup.select.NodeTraversor in project Saber-Bot by notem.
the class HTMLStripper method cleanDescription.
/**
* removes HTML tags from a google calendar event's description
* @param description an event description possibly containing HTML tags
* @return an event description free of HTML tags
*/
public static String cleanDescription(String description) {
FormattingVisitor formatter = new FormattingVisitor();
new NodeTraversor(formatter).traverse(Jsoup.parse(description));
return formatter.toString();
}
Aggregations