@Override public void visit(Node node) { if (node instanceof TextNode || node instanceof Comment || node instanceof DataNode) { node.replaceWith(new TextNode(StringUtils.EMPTY, node.baseUri())); } } }
@Override public void visit(Node node) { if (node instanceof TextNode || node instanceof Comment || node instanceof DataNode) { node.replaceWith(new TextNode(StringUtils.EMPTY, node.baseUri())); } } }
public static Node toTextElement(String str) { Element e = new Element(Tag.valueOf("text"), ""); e.appendText(str); return e; } public static void replaceTextNodes(Node root) { if (root instanceof TextNode) root.replaceWith(toTextElement(((TextNode) root).text())); else for (Node child : root.childNodes()) replaceTextNodes(child); }
public void fixFigrefListItem(Element element) { Node next = element.nextSibling(); String trailingTxt; if (next != null && next instanceof TextNode) { trailingTxt = ((TextNode) next).getWholeText(); } else if (next != null && next instanceof Element) { trailingTxt = ((Element) next).text(); } else { return; } if (trailingTxt.matches("^(, |,? and )")) { next = element.nextSibling().nextSibling(); if (next.nodeName().toLowerCase().equals("b")) { String containedTxt = ((TextNode) next.childNode(0)).getWholeText(); if (containedTxt.matches("[0-9]{1,2}[A-z]?")) { Element newEl = element.clone(); newEl.attr("id", "FR-" + Strings.padStart(containedTxt, 4, '0')); newEl.attr("idref", ReferenceTagger.createFigId(containedTxt)); newEl.tagName("a"); newEl.addClass("figref"); newEl.text(containedTxt); next.replaceWith(newEl); fixFigrefListItem(newEl); } } } }
p.attr("basisInline", "true"); p.html(((TextNode)childNode).text()); childNode.replaceWith(p);