Prevent extra newlines

pull/187/head
M66B 4 years ago
parent 87b5ccb5b9
commit 2b34877425

@ -844,19 +844,42 @@ public class HtmlHelper {
for (Element col : row.children()) { for (Element col : row.children()) {
Element next = col.nextElementSibling(); Element next = col.nextElementSibling();
// Get nodes with content
List<Node> nodes = new ArrayList<>(col.childNodes());
while (nodes.size() > 0) {
Node first = nodes.get(0);
if (first instanceof TextNode && ((TextNode) first).isBlank()) {
nodes.remove(0);
continue;
}
Node last = nodes.get(nodes.size() - 1);
if (last instanceof TextNode && ((TextNode) last).isBlank()) {
nodes.remove(nodes.size() - 1);
continue;
}
break;
}
// Merge single images into next column // Merge single images into next column
if (col.childNodeSize() == 1 && if (nodes.size() == 1) {
(next == null || Node lonely = nodes.get(0);
next.attr("x-align")
.equals(col.attr("x-align")))) { // prevent extra newlines
Node lonely = col.childNode(0); lonely.removeAttr("x-paragraph");
if (lonely instanceof Element &&
"img".equals(lonely.nodeName())) { if (next == null ||
lonely.remove(); next.attr("x-align")
lonely.removeAttr("x-block"); .equals(col.attr("x-align"))) {
merge.add(lonely); if (lonely instanceof Element &&
if (next != null) "img".equals(lonely.nodeName())) {
continue; lonely.remove();
lonely.removeAttr("x-block");
merge.add(lonely);
if (next != null)
continue;
}
} }
} }

Loading…
Cancel
Save