Skip normalizing plain text

This commit is contained in:
M66B 2020-05-05 16:15:49 +02:00
parent 57092f01f0
commit 3f1f8da05c
4 changed files with 17 additions and 9 deletions

View File

@ -75,7 +75,7 @@ public class EditTextCompose extends FixedEditText {
CharSequence text = item.getText();
if (text == null)
return false;
html = "<div>" + HtmlHelper.formatPre(text.toString()) + "</div>";
html = "<div plain=\"true\">" + HtmlHelper.formatPre(text.toString()) + "</div>";
}
Document document = HtmlHelper.sanitizeCompose(context, html, false);

View File

@ -5272,7 +5272,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
// Write decrypted body
String text = Helper.readText(plain);
String html = "<div>" + HtmlHelper.formatPre(text) + "</div>";
String html = "<div plain=\"true\">" + HtmlHelper.formatPre(text) + "</div>";
Helper.writeText(message.getFile(context), html);
db.message().setMessageStored(message.id, new Date().getTime());
db.message().setMessageFts(message.id, false);

View File

@ -446,6 +446,7 @@ public class HtmlHelper {
.addAttributes(":all", "class")
.addAttributes(":all", "style")
.addAttributes("font", "size")
.addAttributes("div", "plain")
.removeTags("col", "colgroup", "thead", "tbody")
.removeAttributes("table", "width")
.removeAttributes("td", "colspan", "rowspan", "width")
@ -731,6 +732,7 @@ public class HtmlHelper {
for (Element pre : document.select("pre")) {
pre.html(formatPre(pre.wholeText()));
pre.tagName("div");
pre.attr("plain", "true");
}
// Code
@ -1311,9 +1313,9 @@ public class HtmlHelper {
for (int j = 0; j < line.length(); j++) {
char kar = line.charAt(j);
if (kar == '\t') {
l.append('\u00A0');
l.append(' ');
while (l.length() % TAB_SIZE != 0)
l.append('\u00A0');
l.append(' ');
} else
l.append(kar);
}
@ -1764,9 +1766,10 @@ public class HtmlHelper {
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
NodeTraversor.traverse(new NodeVisitor() {
private Element element;
private int plain = 0;
private List<TextNode> block = new ArrayList<>();
private String WHITESPACE = " \t\f";
private String WHITESPACE = " \t\f\u00A0";
private String WHITESPACE_NL = WHITESPACE + "\r\n";
private Pattern TRIM_WHITESPACE_NL =
Pattern.compile("[" + WHITESPACE + "]*\\r?\\n[" + WHITESPACE + "]*");
@ -1781,10 +1784,13 @@ public class HtmlHelper {
@Override
public void head(Node node, int depth) {
if (node instanceof TextNode)
block.add((TextNode) node);
else if (node instanceof Element) {
if (node instanceof TextNode) {
if (plain == 0)
block.add((TextNode) node);
} else if (node instanceof Element) {
element = (Element) node;
if ("true".equals(element.attr("plain")))
plain++;
if (BLOCK_START.contains(element.tagName())) {
normalizeText(block);
block.clear();
@ -1796,6 +1802,8 @@ public class HtmlHelper {
public void tail(Node node, int depth) {
if (node instanceof Element) {
element = (Element) node;
if ("true".equals(element.attr("plain")))
plain--;
if (BLOCK_END.contains(element.tagName())) {
normalizeText(block);
block.clear();

View File

@ -1591,7 +1591,7 @@ public class MessageHelper {
if (part.isMimeType("text/plain")) {
if ("flowed".equalsIgnoreCase(ct.getParameter("format")))
result = HtmlHelper.flow(result);
result = "<div>" + HtmlHelper.formatPre(result) + "</div>";
result = "<div plain=\"true\">" + HtmlHelper.formatPre(result) + "</div>";
} else if (part.isMimeType("text/html")) {
if (TextUtils.isEmpty(charset)) {
// <meta charset="utf-8" />