Beispiel #1
0
  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);
  }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 private static void appendWhitespaceIfBr(Element element, StringBuilder accum) {
   if (element.tag.getName().equals("br") && !TextNode.lastCharIsWhitespace(accum))
     accum.append(" ");
 }