/** Get the (unencoded) text of this text node, including any newlines and spaces present in the original. @return text */ public String getWholeText() { return coreValue(); }
/** * Set the text content of this text node. * @param text unencoded text * @return this, for chaining */ public TextNode text(String text) { coreValue(text); return this; }
/** Test if this text node is blank -- that is, empty or only whitespace (including newlines). @return true if this document is empty or only whitespace, false if it contains any text content. */ public boolean isBlank() { return StringUtil.isBlank(coreValue()); }
/** * Split this text node into two nodes at the specified string offset. After splitting, this node will contain the * original text up to the offset, and will have a new text node sibling containing the text after the offset. * @param offset string offset point to split node at. * @return the newly created text node containing the text after the offset. */ public TextNode splitText(int offset) { final String text = coreValue(); Validate.isTrue(offset >= 0, "Split offset must be not be negative"); Validate.isTrue(offset < text.length(), "Split offset must not be greater than current text length"); String head = text.substring(0, offset); String tail = text.substring(offset); text(head); TextNode tailNode = new TextNode(tail); if (parent() != null) parent().addChildren(siblingIndex()+1, tailNode); return tailNode; }
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); }