mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +00:00
Improved pre tag processing
This commit is contained in:
parent
68d421a421
commit
e22dff8cf4
1 changed files with 26 additions and 13 deletions
|
@ -159,23 +159,36 @@ public class HtmlHelper {
|
|||
|
||||
// Pre formatted text
|
||||
for (Element pre : document.select("pre")) {
|
||||
String[] lines = pre.html().split("\\r?\\n");
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
if (!"-- ".equals(lines[i])) {
|
||||
Element div = document.createElement("div");
|
||||
|
||||
for (TextNode tnode : pre.textNodes()) {
|
||||
String[] lines = tnode.getWholeText().split("\\r?\\n");
|
||||
for (String line : lines) {
|
||||
line = Html.escapeHtml(line);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int len = lines[i].length();
|
||||
for (int j = 0; j < len; j++) {
|
||||
char kar = lines[i].charAt(j);
|
||||
if (kar == ' ' && j + 1 < len && lines[i].charAt(j + 1) == ' ')
|
||||
sb.append(" ");
|
||||
else
|
||||
sb.append(kar);
|
||||
if ("-- ".equals(line))
|
||||
sb.append(line);
|
||||
else {
|
||||
int len = line.length();
|
||||
for (int j = 0; j < len; j++) {
|
||||
char kar = line.charAt(j);
|
||||
if (kar == ' ' && j + 1 < len && line.charAt(j + 1) == ' ')
|
||||
sb.append(" ");
|
||||
else
|
||||
sb.append(kar);
|
||||
}
|
||||
}
|
||||
lines[i] = sb.toString();
|
||||
|
||||
Element span = document.createElement("span");
|
||||
span.html(sb.toString());
|
||||
div.appendChild(span);
|
||||
div.appendElement("br");
|
||||
Log.i("span html=" + span.html());
|
||||
}
|
||||
}
|
||||
pre.html(TextUtils.join("<br>", lines));
|
||||
pre.tagName("div");
|
||||
|
||||
pre.replaceWith(div);
|
||||
}
|
||||
|
||||
// Code
|
||||
|
|
Loading…
Reference in a new issue