Check for pasting raw HTML

pull/212/head
M66B 3 years ago
parent 778849fb98
commit dc814cffb9

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

@ -3829,6 +3829,12 @@ public class HtmlHelper {
.remove("x-keep-line"); .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) { static Spanned fromHtml(@NonNull String html, Context context) {
Document document = JsoupEx.parse(html); Document document = JsoupEx.parse(html);
return fromDocument(context, document, null, null); return fromDocument(context, document, null, null);

Loading…
Cancel
Save