Improved pre tag processing

pull/162/head
M66B 5 years ago
parent 68d421a421
commit e22dff8cf4

@ -159,23 +159,36 @@ public class HtmlHelper {
// Pre formatted text // Pre formatted text
for (Element pre : document.select("pre")) { for (Element pre : document.select("pre")) {
String[] lines = pre.html().split("\\r?\\n"); Element div = document.createElement("div");
for (int i = 0; i < lines.length; i++) {
if (!"-- ".equals(lines[i])) { for (TextNode tnode : pre.textNodes()) {
String[] lines = tnode.getWholeText().split("\\r?\\n");
for (String line : lines) {
line = Html.escapeHtml(line);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int len = lines[i].length(); if ("-- ".equals(line))
for (int j = 0; j < len; j++) { sb.append(line);
char kar = lines[i].charAt(j); else {
if (kar == ' ' && j + 1 < len && lines[i].charAt(j + 1) == ' ') int len = line.length();
sb.append("&nbsp;"); for (int j = 0; j < len; j++) {
else char kar = line.charAt(j);
sb.append(kar); if (kar == ' ' && j + 1 < len && line.charAt(j + 1) == ' ')
sb.append("&nbsp;");
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 // Code

Loading…
Cancel
Save