private static void appendNormalisedText(StringBuilder accum, TextNode textNode) { String text = textNode.getWholeText(); if (!preserveWhitespace(textNode.parent())) { text = TextNode.normaliseWhitespace(text); if (TextNode.lastCharIsWhitespace(accum)) text = TextNode.stripLeadingWhitespace(text); } accum.append(text); }
/** * Test if this element has any text content (that is not just whitespace). * * @return true if element has non-blank text content. */ public boolean hasText() { for (Node child : childNodes) { if (child instanceof TextNode) { TextNode textNode = (TextNode) child; if (!textNode.isBlank()) return true; } else if (child instanceof Element) { Element el = (Element) child; if (el.hasText()) return true; } } return false; }
private static void appendWhitespaceIfBr(Element element, StringBuilder accum) { if (element.tag.getName().equals("br") && !TextNode.lastCharIsWhitespace(accum)) accum.append(" "); }