Flowing layout for tables with headers only

pull/187/head
M66B 5 years ago
parent 44f8ee9d86
commit 002c983472

@ -831,20 +831,28 @@ public class HtmlHelper {
Element table = tables.get(t); Element table = tables.get(t);
// Get rows and caption // Get rows and caption
boolean titles = false; Boolean heading = null;
Elements rows = new Elements(); Elements rows = new Elements();
Elements extras = new Elements(); Elements extras = new Elements();
for (Element child : table.children()) { for (Element child : table.children()) {
switch (child.tagName()) { switch (child.tagName()) {
case "thead": case "thead":
case "tfoot": case "tfoot":
titles = true;
case "tbody": case "tbody":
for (Element sub : child.children()) for (Element sub : child.children())
if ("tr".equals(sub.tagName())) if ("tr".equals(sub.tagName())) {
rows.add(sub); rows.add(sub);
else if (!"tbody".equals(child.tagName()) &&
(heading == null || heading))
for (Element col : sub.children()) {
heading = "th".equals(col.tagName());
if (!heading)
break;
}
} else {
Log.e("Row unexpected tag=" + sub.tagName());
extras.add(sub); extras.add(sub);
}
break; break;
case "tr": case "tr":
rows.add(child); rows.add(child);
@ -866,7 +874,8 @@ public class HtmlHelper {
switch (col.tagName()) { switch (col.tagName()) {
case "td": case "td":
if (!titles && col.childNodeSize() == 1) { if (col.childNodeSize() == 1 &&
(heading == null || !heading)) {
Node first = col.childNode(0); Node first = col.childNode(0);
if (first instanceof TextNode) { if (first instanceof TextNode) {
if (((TextNode) first).text().length() != 1) if (((TextNode) first).text().length() != 1)
@ -888,7 +897,7 @@ public class HtmlHelper {
col.appendChild(strong); col.appendChild(strong);
break; break;
default: default:
Log.e("Column expected tag=" + col.tagName()); Log.e("Column unexpected tag=" + col.tagName());
if (tdebug) { if (tdebug) {
col.prependText("COLUMN=" + col.tagName() + "["); col.prependText("COLUMN=" + col.tagName() + "[");
col.appendText("]"); col.appendText("]");
@ -932,21 +941,39 @@ public class HtmlHelper {
node.remove(); node.remove();
if (node instanceof Element) if (node instanceof Element)
node.removeAttr("x-block"); node.removeAttr("x-block");
row.child(col + 1).prependText(" ").prependChild(node); row.child(col + 1).prependText("\u00a0").prependChild(node);
} }
// Rebuild table // Rebuild table
table.tagName("div"); table.tagName("div");
table.children().remove(); // leaves nodes table.children().remove(); // leaves nodes
// Process extras: caption, etc
for (Element extra : extras) { for (Element extra : extras) {
if (tdebug) { if (tdebug) {
extra.prependText("EXTRA=" + extra.tagName() + "["); extra.prependText("EXTRA=" + extra.tagName() + "[");
extra.appendText("]"); extra.appendText("]");
} }
table.appendChild(extra.tagName("div").attr("x-block", "true")); table.appendChild(extra.tagName("div")
.attr("x-block", "true"));
} }
if (heading == null || !heading) {
for (Element row : rows) {
Element line = document.createElement("div")
.attr("x-block", "true");
for (Element col : row.children())
line.appendChild(col.tagName("div"));
table.appendChild(line);
if (text_separators && view)
line.appendElement("hr")
.attr("x-block", "true")
.attr("x-dashed", "true");
}
} else {
// Process columns
for (int c = 0; c < maxcols; c++) { for (int c = 0; c < maxcols; c++) {
Element col = document.createElement("div") Element col = document.createElement("div")
.attr("x-block", "true"); .attr("x-block", "true");
@ -988,6 +1015,7 @@ public class HtmlHelper {
.attr("x-dashed", "true"); .attr("x-dashed", "true");
} }
} }
}
// Images // Images
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img

Loading…
Cancel
Save