@Override public void handleTextNode(TextNode node, DocumentConverter converter) { // Override to provide special handling for ignoring // leading or trailing all-space nodes. if((node.previousSibling() != null && node.nextSibling() != null) || node.text().trim().length() != 0) { super.handleTextNode(node, converter); } }
private String getTextNodeText(TextNode tn, boolean normalText) { String input = normalText ? tn.text() : tn.getWholeText(); Node prev = tn.previousSibling(); Node next = tn.nextSibling(); boolean parentIsBlock = isBlock(tn.parent()); if(isBlock(prev)) { input = ltrim(input); } else if(prev == null && parentIsBlock) { input = ltrim(input); } else if(normalText && prev instanceof TextNode) { TextNode tprev = (TextNode)prev; if(EMPTY_MATCHER.matcher(tprev.text()).matches()) { input = ltrim(input); } } if(input.length() > 0) { if(isBlock(next)) { input = rtrim(input); } else if(next == null && parentIsBlock) { input = rtrim(input); } else if(normalText && next instanceof TextNode) { TextNode tnext = (TextNode)next; if(EMPTY_MATCHER.matcher(tnext.text()).matches()) { input = rtrim(input); } } } return input; }