MCPcopy Create free account
hub / github.com/M66B/FairEmail / getText

Method getText

app/src/main/java/eu/faircode/email/HtmlHelper.java:2999–3105  ·  view source on GitHub ↗
(Context context, String html)

Source from the content-addressed store, hash-verified

2997 }
2998
2999 @NonNull
3000 static String getText(Context context, String html) {
3001 Document d = sanitizeCompose(context, html, false);
3002
3003 truncate(d, getMaxFormatTextSize(context));
3004
3005 SpannableStringBuilder ssb = fromDocument(context, d, null, null);
3006
3007 for (UnderlineSpan span : ssb.getSpans(0, ssb.length(), UnderlineSpan.class)) {
3008 int start = ssb.getSpanStart(span);
3009 int end = ssb.getSpanEnd(span);
3010 ssb.insert(end, "_");
3011 ssb.insert(start, "_");
3012 }
3013
3014 for (StyleSpan span : ssb.getSpans(0, ssb.length(), StyleSpan.class)) {
3015 int start = ssb.getSpanStart(span);
3016 int end = ssb.getSpanEnd(span);
3017 if (span.getStyle() == Typeface.ITALIC) {
3018 ssb.insert(end, "/");
3019 ssb.insert(start, "/");
3020 } else if (span.getStyle() == Typeface.BOLD) {
3021 ssb.insert(end, "*");
3022 ssb.insert(start, "*");
3023 }
3024 }
3025
3026 for (URLSpan span : ssb.getSpans(0, ssb.length(), URLSpan.class)) {
3027 String url = span.getURL();
3028 if (TextUtils.isEmpty(url))
3029 continue;
3030
3031 if (url.toLowerCase(Locale.ROOT).startsWith("mailto:"))
3032 url = url.substring("mailto:".length());
3033
3034 int start = ssb.getSpanStart(span);
3035 int end = ssb.getSpanEnd(span);
3036 String text = ssb.subSequence(start, end).toString();
3037 if (!text.contains(url))
3038 ssb.insert(end, "[" + url + "]");
3039 }
3040
3041 for (ImageSpan span : ssb.getSpans(0, ssb.length(), ImageSpan.class)) {
3042 String source = span.getSource();
3043 if (TextUtils.isEmpty(source))
3044 continue;
3045
3046 int start = ssb.getSpanStart(span);
3047 int end = ssb.getSpanEnd(span);
3048
3049 if (!source.toLowerCase(Locale.ROOT).startsWith("data:"))
3050 ssb.insert(end, "[" + context.getString(R.string.title_avatar) + "]");
3051
3052 for (int i = start; i < end; i++)
3053 if (ssb.charAt(i) == '\uFFFC') {
3054 ssb.delete(i, i + 1);
3055 end--;
3056 }

Callers 15

onClickMethod · 0.95
onExecuteMethod · 0.95
copyRefMethod · 0.95
onItemClickMethod · 0.95
getIntentIssueMethod · 0.95
onExecuteMethod · 0.95
buildMethod · 0.95
onClickMethod · 0.45
onAuthorizedMethod · 0.45
bindToMethod · 0.45
onSaveInstanceStateMethod · 0.45
onClickMethod · 0.45

Calls 15

sanitizeComposeMethod · 0.95
truncateMethod · 0.95
getMaxFormatTextSizeMethod · 0.95
fromDocumentMethod · 0.95
getIndexMethod · 0.95
getLevelMethod · 0.95
getLTypeMethod · 0.95
getLevelMethod · 0.95
getSourceMethod · 0.80
charAtMethod · 0.80
getSpansMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected