mirror of https://github.com/M66B/FairEmail.git
Added detect HTML
This commit is contained in:
parent
cc44993d1c
commit
e29be73126
|
@ -46,3 +46,4 @@ FairEmail uses:
|
|||
* [IPAddress](https://github.com/seancfoley/IPAddress). Copyright 2016-2018 Sean C Foley. [Apache License 2.0](https://github.com/seancfoley/IPAddress/blob/master/LICENSE).
|
||||
* [MaterialDings](https://github.com/Accusoft/MaterialDings). Copyright (c) 2018 Accusoft Corporation. [MIT License](https://github.com/Accusoft/MaterialDings/blob/master/LICENSE.md).
|
||||
* [Send](https://github.com/timvisee/send). [Mozilla Public License 2.0](https://github.com/timvisee/send/blob/master/LICENSE).
|
||||
* [DetectHtml](https://github.com/dbennett455/DetectHtml). [The MIT License](https://github.com/dbennett455/DetectHtml/blob/master/LICENSE).
|
||||
|
|
|
@ -46,3 +46,4 @@ FairEmail uses:
|
|||
* [IPAddress](https://github.com/seancfoley/IPAddress). Copyright 2016-2018 Sean C Foley. [Apache License 2.0](https://github.com/seancfoley/IPAddress/blob/master/LICENSE).
|
||||
* [MaterialDings](https://github.com/Accusoft/MaterialDings). Copyright (c) 2018 Accusoft Corporation. [MIT License](https://github.com/Accusoft/MaterialDings/blob/master/LICENSE.md).
|
||||
* [Send](https://github.com/timvisee/send). [Mozilla Public License 2.0](https://github.com/timvisee/send/blob/master/LICENSE).
|
||||
* [DetectHtml](https://github.com/dbennett455/DetectHtml). [The MIT License](https://github.com/dbennett455/DetectHtml/blob/master/LICENSE).
|
||||
|
|
|
@ -55,6 +55,7 @@ import androidx.core.view.inputmethod.InputConnectionCompat;
|
|||
import androidx.core.view.inputmethod.InputContentInfoCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.github.DetectHtml;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
||||
|
@ -487,7 +488,7 @@ public class EditTextCompose extends FixedEditText {
|
|||
String h = null;
|
||||
if (raw) {
|
||||
CharSequence text = item.getText();
|
||||
if (text != null && HtmlHelper.isHtml(text.toString()))
|
||||
if (text != null && DetectHtml.isHtml(text.toString()))
|
||||
h = text.toString();
|
||||
}
|
||||
if (h == null)
|
||||
|
|
|
@ -3829,12 +3829,6 @@ 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);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package org.github;
|
||||
|
||||
/**
|
||||
* Detect HTML markup in a string
|
||||
* This will detect tags or entities
|
||||
*
|
||||
* @author dbennett455@gmail.com - David H. Bennett
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DetectHtml
|
||||
{
|
||||
// adapted from post by Phil Haack and modified to match better
|
||||
public final static String tagStart=
|
||||
"\\<\\w+((\\s+\\w+(\\s*\\=\\s*(?:\".*?\"|'.*?'|[^'\"\\>\\s]+))?)+\\s*|\\s*)\\>";
|
||||
public final static String tagEnd=
|
||||
"\\</\\w+\\>";
|
||||
public final static String tagSelfClosing=
|
||||
"\\<\\w+((\\s+\\w+(\\s*\\=\\s*(?:\".*?\"|'.*?'|[^'\"\\>\\s]+))?)+\\s*|\\s*)/\\>";
|
||||
public final static String htmlEntity=
|
||||
"&[a-zA-Z][a-zA-Z0-9]+;";
|
||||
public final static Pattern htmlPattern=Pattern.compile(
|
||||
"("+tagStart+".*"+tagEnd+")|("+tagSelfClosing+")|("+htmlEntity+")",
|
||||
Pattern.DOTALL
|
||||
);
|
||||
|
||||
/**
|
||||
* Will return true if s contains HTML markup tags or entities.
|
||||
*
|
||||
* @param s String to test
|
||||
* @return true if string contains HTML
|
||||
*/
|
||||
public static boolean isHtml(String s) {
|
||||
boolean ret=false;
|
||||
if (s != null) {
|
||||
ret=htmlPattern.matcher(s).find();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue