Replace Apple converted spaces

This commit is contained in:
M66B 2020-02-14 13:31:34 +01:00
parent 62ade02d3e
commit d074b0c3c7
2 changed files with 17 additions and 6 deletions

View File

@ -1696,6 +1696,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
args.putBoolean("signed_data", signed_data);
Document document = JsoupEx.parse(body);
HtmlHelper.cleanup(document);
// Check for inline encryption
int begin = body.indexOf(Helper.PGP_BEGIN_MESSAGE);
@ -1760,7 +1761,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return document.html();
} else {
// Cleanup message
document = HtmlHelper.sanitize(context, body, show_images, true, true);
document = HtmlHelper.sanitize(context, document, show_images, true, true);
// Collapse quotes
if (!show_quotes) {

View File

@ -239,12 +239,13 @@ public class HtmlHelper {
}
static Document sanitize(Context context, String html, boolean show_images, boolean autolink) {
return sanitize(context, html, show_images, autolink, false);
Document parsed = JsoupEx.parse(html);
return sanitize(context, parsed, show_images, autolink, false);
}
static Document sanitize(Context context, String html, boolean show_images, boolean autolink, boolean more) {
static Document sanitize(Context context, Document parsed, boolean show_images, boolean autolink, boolean more) {
try {
return _sanitize(context, html, show_images, autolink, more);
return _sanitize(context, parsed, show_images, autolink, more);
} catch (Throwable ex) {
// OutOfMemoryError
Log.e(ex);
@ -256,14 +257,13 @@ public class HtmlHelper {
}
}
private static Document _sanitize(Context context, String html, boolean show_images, boolean autolink, boolean more) {
private static Document _sanitize(Context context, Document parsed, boolean show_images, boolean autolink, boolean more) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true);
boolean display_hidden = prefs.getBoolean("display_hidden", false);
boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
// https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css
Document parsed = JsoupEx.parse(html);
// <!--[if ...]><!--> ... <!--<![endif]-->
// https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/compatibility/hh801214(v=vs.85)
@ -1197,6 +1197,16 @@ public class HtmlHelper {
return ssb;
}
static void cleanup(Document d) {
for (Element aspace : d.select(".Apple-converted-space"))
if (aspace.previousSibling() instanceof TextNode) {
TextNode tnode = (TextNode) aspace.previousSibling();
tnode.text(tnode.text() + " ");
aspace.remove();
} else
aspace.replaceWith(new TextNode(" "));
}
static boolean truncate(Document d, boolean reformat) {
int at = (reformat ? MAX_FORMAT_TEXT_SIZE : MAX_FULL_TEXT_SIZE);