/** * Create and prepend a new TextNode to this element. * * @param text the unencoded text to add * @return this element */ public Element prependText(String text) { Validate.notNull(text); TextNode node = new TextNode(text); prependChild(node); return this; }
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); } }
/** * Create a new element by tag name, and add it as the first child. * * @param tagName the name of the tag (e.g. {@code div}). * @return the new element, to allow you to add content to it, e.g.: * {@code parent.prependElement("h1").attr("id", "header").text("Welcome");} */ public Element prependElement(String tagName) { Element child = new Element(Tag.valueOf(tagName), baseUri()); prependChild(child); return child; }
public Element prependChild(Node child) { return originElement.prependChild(child); }
body.prependChild(elements.get(index));
body.prependChild(elements.get(index));
private void addHiddenInputTag(Element form, String formIdAttrName, String formIdAttrValue) { Attributes attributes = Stream.of( new Attribute("type", "hidden"), new Attribute("name", formIdAttrName), new Attribute("value", formIdAttrValue)) .collect(Attributes::new, Attributes::put, Attributes::addAll); form.prependChild(new Element(Tag.valueOf("input"), "/", attributes)); }
/** * Corrects table headers by adding a {@code <thead>} section where missing. * <p> * This serves to fix an error with tables created by Doxia, which will add * the header rows into the {@code <tbody>} element, instead on a {@code * <thead>} element. * * @param root * root element with tables to fix */ public final void updateTableHeads(final Element root) { final Iterable<Element> tableHeadRows; // Heads to fix Element table; // HTML table Element thead; // Table's head for wrapping checkNotNull(root, "Received a null pointer as root element"); // Table rows with <th> tags in a <tbody> tableHeadRows = root.select("table > tbody > tr:has(th)"); for (final Element row : tableHeadRows) { // Gets the row's table // The selector ensured the row is inside a tbody table = row.parent().parent(); // Removes the row from its original position row.remove(); // Creates a table header element with the row thead = new Element(Tag.valueOf("thead"), ""); thead.appendChild(row); // Adds the head at the beginning of the table table.prependChild(thead); } }
thead.appendChild(row); table.prependChild(thead);
thead.appendChild(row); table.prependChild(thead);
paragraph.prependChild(child.clone()); body.prependChild(lastParagraph);
paragraph.prependChild(child.clone()); body.prependChild(lastParagraph);
mDocument.body().prependChild(overlay);