Check for pasting raw HTML

This commit is contained in:
M66B 2023-01-18 22:29:37 +01:00
parent 778849fb98
commit dc814cffb9
2 changed files with 16 additions and 3 deletions

View File

@ -484,7 +484,14 @@ public class EditTextCompose extends FixedEditText {
ClipData.Item item = cbm.getPrimaryClip().getItemAt(0);
final String html;
String h = item.getHtmlText();
String h = null;
if (raw) {
CharSequence text = item.getText();
if (text != null && HtmlHelper.isHtml(text.toString()))
h = text.toString();
}
if (h == null)
h = item.getHtmlText();
if (h == null) {
CharSequence text = item.getText();
if (text == null)
@ -497,9 +504,9 @@ public class EditTextCompose extends FixedEditText {
@Override
public void run() {
try {
SpannableStringBuilder ssb = (raw)
SpannableStringBuilder ssb = (raw
? new SpannableStringBuilderEx(html)
: getSpanned(context, html);
: getSpanned(context, html));
EditTextCompose.this.post(new Runnable() {
@Override

View File

@ -3829,6 +3829,12 @@ public class HtmlHelper {
.remove("x-keep-line");
}
static boolean isHtml(String text) {
Pattern p = Pattern.compile(".*\\<[^>]+>.*", Pattern.DOTALL);
boolean isHtml = p.matcher(text).matches();
return isHtml;
}
static Spanned fromHtml(@NonNull String html, Context context) {
Document document = JsoupEx.parse(html);
return fromDocument(context, document, null, null);