/** 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 void normaliseTextNodes(Element element) { List<Node> toMove = new ArrayList<>(); for (Node node: element.childNodes) { if (node instanceof TextNode) { TextNode tn = (TextNode) node; if (!tn.isBlank()) toMove.add(tn); } } for (int i = toMove.size()-1; i >= 0; i--) { Node node = toMove.get(i); element.removeChild(node); body().prependChild(new TextNode(" ")); body().prependChild(node); } }
void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { if (out.prettyPrint() && ((siblingIndex() == 0 && parentNode instanceof Element && ((Element) parentNode).tag().formatAsBlock() && !isBlank()) || (out.outline() && siblingNodes().size()>0 && !isBlank()) )) indent(accum, depth, out); boolean normaliseWhite = out.prettyPrint() && parent() instanceof Element && !Element.preserveWhitespace(parent()); Entities.escape(accum, coreValue(), out, false, normaliseWhite, false); }
private Element nextTag(Tag tag, Element current) { Element nextTag = null; for (Node nextNode = current; (nextNode = nextNode.nextSibling()) != null;) { if (nextNode instanceof Element) { Element nextElement = (Element) nextNode; if (tag.equals(nextElement.tag())) { nextTag = nextElement; } break; } else if (nextNode instanceof TextNode && !((TextNode) nextNode).isBlank()) { break; } } return nextTag; }
MDLine line = getLastLine(lines); if (line.getContent().equals("")) { if (!textNode.isBlank()) { line.append(textNode.text().replaceAll("#", "/#").replaceAll("\\*", "/\\*"));
private Element nextTag(Tag tag, Element current) { Element nextTag = null; for (Node nextNode = current; (nextNode = nextNode.nextSibling()) != null; ) { if (nextNode instanceof Element) { Element nextElement = (Element) nextNode; if (tag.equals(nextElement.tag())) { nextTag = nextElement; } break; } else if (nextNode instanceof TextNode && !((TextNode) nextNode).isBlank()) { break; } } return nextTag; }