mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-04 06:20:26 +00:00
Trivial column merger
This commit is contained in:
parent
719de5de43
commit
8146c5243a
1 changed files with 36 additions and 1 deletions
|
@ -55,6 +55,7 @@ import android.text.style.URLSpan;
|
||||||
import android.text.style.UnderlineSpan;
|
import android.text.style.UnderlineSpan;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
|
import android.util.SparseBooleanArray;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.textclassifier.TextClassificationManager;
|
import android.view.textclassifier.TextClassificationManager;
|
||||||
import android.view.textclassifier.TextLanguage;
|
import android.view.textclassifier.TextLanguage;
|
||||||
|
@ -830,13 +831,15 @@ public class HtmlHelper {
|
||||||
Element table = tables.get(t);
|
Element table = tables.get(t);
|
||||||
|
|
||||||
// Get rows and caption
|
// Get rows and caption
|
||||||
|
boolean titles = false;
|
||||||
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 "tbody":
|
|
||||||
case "tfoot":
|
case "tfoot":
|
||||||
|
titles = true;
|
||||||
|
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);
|
||||||
|
@ -854,6 +857,8 @@ public class HtmlHelper {
|
||||||
|
|
||||||
// Process column spans
|
// Process column spans
|
||||||
int maxcols = 0;
|
int maxcols = 0;
|
||||||
|
int mincols = Integer.MAX_VALUE;
|
||||||
|
SparseBooleanArray nomerge = new SparseBooleanArray();
|
||||||
for (Element row : rows) {
|
for (Element row : rows) {
|
||||||
int cols = 0;
|
int cols = 0;
|
||||||
for (Element col : row.children()) {
|
for (Element col : row.children()) {
|
||||||
|
@ -861,8 +866,20 @@ public class HtmlHelper {
|
||||||
|
|
||||||
switch (col.tagName()) {
|
switch (col.tagName()) {
|
||||||
case "td":
|
case "td":
|
||||||
|
if (!titles && col.childNodeSize() == 1) {
|
||||||
|
Node first = col.childNode(0);
|
||||||
|
if (first instanceof TextNode) {
|
||||||
|
if (((TextNode) first).text().length() != 1)
|
||||||
|
nomerge.put(cols - 1, true);
|
||||||
|
} else {
|
||||||
|
if (!"img".equals(first.nodeName()))
|
||||||
|
nomerge.put(cols - 1, true);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
nomerge.put(cols - 1, true);
|
||||||
break;
|
break;
|
||||||
case "th":
|
case "th":
|
||||||
|
nomerge.put(cols - 1, true);
|
||||||
Element strong = new Element("strong");
|
Element strong = new Element("strong");
|
||||||
for (Node child : new ArrayList<>(col.childNodes())) {
|
for (Node child : new ArrayList<>(col.childNodes())) {
|
||||||
child.remove();
|
child.remove();
|
||||||
|
@ -900,7 +917,23 @@ public class HtmlHelper {
|
||||||
}
|
}
|
||||||
if (cols > maxcols)
|
if (cols > maxcols)
|
||||||
maxcols = cols;
|
maxcols = cols;
|
||||||
|
if (cols < mincols)
|
||||||
|
mincols = cols;
|
||||||
}
|
}
|
||||||
|
if (mincols > maxcols)
|
||||||
|
mincols = maxcols;
|
||||||
|
|
||||||
|
// Merge columns
|
||||||
|
if (mincols > 1)
|
||||||
|
for (int col = 0; col < mincols - 1; col++)
|
||||||
|
if (!nomerge.get(col))
|
||||||
|
for (Element row : rows) {
|
||||||
|
Node node = row.child(col).childNode(0);
|
||||||
|
node.remove();
|
||||||
|
if (node instanceof Element)
|
||||||
|
node.removeAttr("x-block");
|
||||||
|
row.child(col + 1).prependText(" ").prependChild(node);
|
||||||
|
}
|
||||||
|
|
||||||
// Rebuild table
|
// Rebuild table
|
||||||
table.tagName("div");
|
table.tagName("div");
|
||||||
|
@ -917,6 +950,8 @@ public class HtmlHelper {
|
||||||
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");
|
||||||
|
if (tdebug)
|
||||||
|
col.appendText("merge=" + !nomerge.get(c));
|
||||||
int r = 0;
|
int r = 0;
|
||||||
for (Element row : rows) {
|
for (Element row : rows) {
|
||||||
r++;
|
r++;
|
||||||
|
|
Loading…
Reference in a new issue