2022-10-02 23:06:56 +02:00
|
|
|
package android.text;
|
|
|
|
|
|
2024-08-05 17:17:53 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
|
|
2022-10-02 23:06:56 +02:00
|
|
|
public class Html {
|
2024-08-05 17:17:53 +02:00
|
|
|
|
|
|
|
|
public static interface ImageGetter {
|
|
|
|
|
public Drawable getDrawable(String source);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public static Spanned fromHtml(String source) {
|
2024-03-10 16:06:41 +01:00
|
|
|
return new SpannableString(source.replace("<br/>", "\n")
|
|
|
|
|
.replace("<br>", "\n")
|
|
|
|
|
.replace(" ", " "));
|
|
|
|
|
// TODO when JTidy is in use: s/<br \/>//g
|
2023-06-22 11:45:46 +02:00
|
|
|
}
|
2024-02-17 15:15:05 +01:00
|
|
|
|
|
|
|
|
public static String escapeHtml(CharSequence source) {
|
|
|
|
|
StringBuilder out = new StringBuilder(source.length());
|
|
|
|
|
for (int i = 0; i < source.length(); i++) {
|
|
|
|
|
char c = source.charAt(i);
|
|
|
|
|
if (c == '<' || c == '>' || c == '&' || c == '"' || c == '\'' || c > 0x7F) {
|
|
|
|
|
out.append("&#");
|
|
|
|
|
out.append((int) c);
|
|
|
|
|
out.append(';');
|
|
|
|
|
} else {
|
|
|
|
|
out.append(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return out.toString();
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|