|
|
@ -1587,7 +1587,7 @@ public class HtmlHelper {
|
|
|
|
|
|
|
|
|
|
|
|
truncate(d, true);
|
|
|
|
truncate(d, true);
|
|
|
|
|
|
|
|
|
|
|
|
SpannableStringBuilder ssb = fromDocument(context, d, false, null, null);
|
|
|
|
SpannableStringBuilder ssb = fromDocument(context, d, false, true, null, null);
|
|
|
|
|
|
|
|
|
|
|
|
for (URLSpan span : ssb.getSpans(0, ssb.length(), URLSpan.class)) {
|
|
|
|
for (URLSpan span : ssb.getSpans(0, ssb.length(), URLSpan.class)) {
|
|
|
|
String url = span.getURL();
|
|
|
|
String url = span.getURL();
|
|
|
@ -1804,15 +1804,16 @@ public class HtmlHelper {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SpannableStringBuilder fromDocument(Context context, @NonNull Document document) {
|
|
|
|
static SpannableStringBuilder fromDocument(
|
|
|
|
return fromDocument(context, document, null, null);
|
|
|
|
Context context, @NonNull Document document, boolean compress,
|
|
|
|
|
|
|
|
@Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
|
|
|
|
|
|
|
return fromDocument(context, document, true, compress, imageGetter, tagHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SpannableStringBuilder fromDocument(Context context, @NonNull Document document, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
|
|
|
private static SpannableStringBuilder fromDocument(
|
|
|
|
return fromDocument(context, document, true, imageGetter, tagHandler);
|
|
|
|
Context context, @NonNull Document document,
|
|
|
|
}
|
|
|
|
final boolean warn, final boolean compress,
|
|
|
|
|
|
|
|
@Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
|
|
|
private static SpannableStringBuilder fromDocument(Context context, @NonNull Document document, final boolean warn, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
boolean debug = prefs.getBoolean("debug", false);
|
|
|
|
boolean debug = prefs.getBoolean("debug", false);
|
|
|
|
|
|
|
|
|
|
|
@ -2179,6 +2180,8 @@ public class HtmlHelper {
|
|
|
|
|
|
|
|
|
|
|
|
private void newline(int index) {
|
|
|
|
private void newline(int index) {
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (compress) {
|
|
|
|
int i = Math.min(index, ssb.length() - 1);
|
|
|
|
int i = Math.min(index, ssb.length() - 1);
|
|
|
|
while (i >= 0) {
|
|
|
|
while (i >= 0) {
|
|
|
|
char kar = ssb.charAt(i);
|
|
|
|
char kar = ssb.charAt(i);
|
|
|
@ -2188,6 +2191,7 @@ public class HtmlHelper {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
i--;
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (count < 2)
|
|
|
|
if (count < 2)
|
|
|
|
ssb.insert(index, "\n");
|
|
|
|
ssb.insert(index, "\n");
|
|
|
@ -2219,15 +2223,13 @@ public class HtmlHelper {
|
|
|
|
return ssb;
|
|
|
|
return ssb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Spanned fromHtml(@NonNull String html, Context context) {
|
|
|
|
static Spanned fromHtml(@NonNull String html, boolean compress, Context context) {
|
|
|
|
return fromHtml(html, null, null, context);
|
|
|
|
return fromHtml(html, compress, null, null, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Spanned fromHtml(@NonNull String html, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler, Context context) {
|
|
|
|
static Spanned fromHtml(@NonNull String html, boolean compress, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler, Context context) {
|
|
|
|
Document document = JsoupEx.parse(html);
|
|
|
|
Document document = JsoupEx.parse(html);
|
|
|
|
return fromDocument(context, document, false, imageGetter, tagHandler);
|
|
|
|
Spanned spanned = fromDocument(context, document, false, compress, imageGetter, tagHandler);
|
|
|
|
/*
|
|
|
|
|
|
|
|
Spanned spanned = HtmlCompat.fromHtml(html, FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM, imageGetter, tagHandler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int i = spanned.length();
|
|
|
|
int i = spanned.length();
|
|
|
|
while (i > 1 && spanned.charAt(i - 2) == '\n' && spanned.charAt(i - 1) == '\n')
|
|
|
|
while (i > 1 && spanned.charAt(i - 2) == '\n' && spanned.charAt(i - 1) == '\n')
|
|
|
@ -2235,8 +2237,7 @@ public class HtmlHelper {
|
|
|
|
if (i != spanned.length())
|
|
|
|
if (i != spanned.length())
|
|
|
|
spanned = (Spanned) spanned.subSequence(0, i);
|
|
|
|
spanned = (Spanned) spanned.subSequence(0, i);
|
|
|
|
|
|
|
|
|
|
|
|
return reverseSpans(spanned);
|
|
|
|
return spanned;
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static String toHtml(Spanned spanned, Context context) {
|
|
|
|
static String toHtml(Spanned spanned, Context context) {
|
|
|
|