void (Element element) { List<Content> children = element.getContent(); for (int i = 0; i < children.size() - 2; i++) { Content c1 = children.get(i); Content c2 = children.get(i + 1); Content c3 = children.get(i + 2); if (c1 instanceof Element && c2 instanceof Text && c3 instanceof Element && (hasLineBreak((Element)c1) || hasLineBreak((Element)c3)) && isOneEOFText(((Text)c2).getText())) { element.setContent(i + 1, new Text(((Text)c2).getText().replace("\n", "\n\n"))); } } }