Disable autolink for composer

pull/168/head
M66B 5 years ago
parent 12f0b169a6
commit 44dd58d0d1

@ -139,7 +139,7 @@ public class ActivityEML extends ActivityBase {
String html = result.parts.getHtml(context);
if (html != null)
result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(context, html, false));
result.body = HtmlHelper.fromHtml(HtmlHelper.sanitize(context, html, false, false));
return result;
}

@ -1449,7 +1449,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return document.html();
} else {
// Cleanup message
String html = HtmlHelper.sanitize(context, body, show_images);
String html = HtmlHelper.sanitize(context, body, show_images, true);
// Collapse quotes
if (!show_quotes) {

@ -68,7 +68,7 @@ public class EditTextCompose extends AppCompatEditText {
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
String html = item.coerceToHtmlText(context);
html = HtmlHelper.sanitize(context, html, false);
html = HtmlHelper.sanitize(context, html, false, false);
Spanned paste = HtmlHelper.fromHtml(html);
int start = getSelectionStart();

@ -781,7 +781,7 @@ public class FragmentCompose extends FragmentBase {
String text = HtmlHelper.getText(ref);
html = "<p>" + text.replaceAll("\\r?\\n", "<br>") + "</p>";
} else
html = HtmlHelper.sanitize(context, ref, true);
html = HtmlHelper.sanitize(context, ref, true, false);
refFile.delete();
return body + html;
@ -2235,7 +2235,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.subject = args.getString("subject", "");
body = args.getString("body", "");
if (!TextUtils.isEmpty(body))
body = HtmlHelper.sanitize(context, body, false);
body = HtmlHelper.sanitize(context, body, false, false);
if (answer > 0) {
EntityAnswer a = db.answer().getAnswer(answer);
@ -2309,7 +2309,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.subject = ref.subject;
if (ref.content) {
String html = Helper.readText(ref.getFile(context));
body = HtmlHelper.sanitize(context, html, true);
body = HtmlHelper.sanitize(context, html, true, false);
}
} else if ("list".equals(action)) {
data.draft.subject = ref.subject;
@ -2596,7 +2596,7 @@ public class FragmentCompose extends FragmentBase {
if (data.draft.content) {
File file = data.draft.getFile(context);
String html = Helper.readText(file);
html = HtmlHelper.sanitize(context, html, true);
html = HtmlHelper.sanitize(context, html, true, false);
Helper.writeText(file, html);
} else {
if (data.draft.uid == null)
@ -3316,7 +3316,7 @@ public class FragmentCompose extends FragmentBase {
Spanned spannedRef = null;
File refFile = draft.getRefFile(context);
if (refFile.exists()) {
String quote = HtmlHelper.sanitize(context, Helper.readText(refFile), show_images);
String quote = HtmlHelper.sanitize(context, Helper.readText(refFile), show_images, false);
Spanned spannedQuote = HtmlHelper.fromHtml(quote,
new Html.ImageGetter() {
@Override

@ -80,9 +80,9 @@ public class HtmlHelper {
private static final List<String> tails = Collections.unmodifiableList(Arrays.asList(
"h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li"));
static String sanitize(Context context, String html, boolean show_images) {
static String sanitize(Context context, String html, boolean show_images, boolean autolink) {
try {
return _sanitize(context, html, show_images);
return _sanitize(context, html, show_images, autolink);
} catch (Throwable ex) {
// OutOfMemoryError
Log.e(ex);
@ -90,7 +90,7 @@ public class HtmlHelper {
}
}
private static String _sanitize(Context context, String html, boolean show_images) {
private static String _sanitize(Context context, String html, boolean show_images, boolean autolink) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true);
boolean display_hidden = prefs.getBoolean("display_hidden", false);
@ -450,69 +450,71 @@ public class HtmlHelper {
}
// Autolink
final Pattern pattern = Pattern.compile(
PatternsCompat.AUTOLINK_EMAIL_ADDRESS.pattern() + "|" +
PatternsCompat.AUTOLINK_WEB_URL.pattern());
NodeTraversor.traverse(new NodeVisitor() {
private int links = 0;
@Override
public void head(Node node, int depth) {
if (links < MAX_AUTO_LINK && node instanceof TextNode) {
TextNode tnode = (TextNode) node;
String text = tnode.getWholeText();
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
Element span = document.createElement("span");
int pos = 0;
do {
boolean linked = false;
Node parent = tnode.parent();
while (parent != null) {
if ("a".equals(parent.nodeName())) {
linked = true;
break;
if (autolink) {
final Pattern pattern = Pattern.compile(
PatternsCompat.AUTOLINK_EMAIL_ADDRESS.pattern() + "|" +
PatternsCompat.AUTOLINK_WEB_URL.pattern());
NodeTraversor.traverse(new NodeVisitor() {
private int links = 0;
@Override
public void head(Node node, int depth) {
if (links < MAX_AUTO_LINK && node instanceof TextNode) {
TextNode tnode = (TextNode) node;
String text = tnode.getWholeText();
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
Element span = document.createElement("span");
int pos = 0;
do {
boolean linked = false;
Node parent = tnode.parent();
while (parent != null) {
if ("a".equals(parent.nodeName())) {
linked = true;
break;
}
parent = parent.parent();
}
parent = parent.parent();
}
boolean email = matcher.group().contains("@") && !matcher.group().contains(":");
if (BuildConfig.DEBUG)
Log.i("Web url=" + matcher.group() +
" " + matcher.start() + "..." + matcher.end() + "/" + text.length() +
" linked=" + linked + " email=" + email + " count=" + links);
boolean email = matcher.group().contains("@") && !matcher.group().contains(":");
if (BuildConfig.DEBUG)
Log.i("Web url=" + matcher.group() +
" " + matcher.start() + "..." + matcher.end() + "/" + text.length() +
" linked=" + linked + " email=" + email + " count=" + links);
if (linked)
span.appendText(text.substring(pos, matcher.end()));
else {
span.appendText(text.substring(pos, matcher.start()));
if (linked)
span.appendText(text.substring(pos, matcher.end()));
else {
span.appendText(text.substring(pos, matcher.start()));
Element a = document.createElement("a");
a.attr("href", (email ? "mailto:" : "") + matcher.group());
a.text(matcher.group());
span.appendChild(a);
Element a = document.createElement("a");
a.attr("href", (email ? "mailto:" : "") + matcher.group());
a.text(matcher.group());
span.appendChild(a);
links++;
}
links++;
}
pos = matcher.end();
} while (links < MAX_AUTO_LINK && matcher.find());
pos = matcher.end();
} while (links < MAX_AUTO_LINK && matcher.find());
span.appendText(text.substring(pos));
span.appendText(text.substring(pos));
tnode.before(span);
tnode.text("");
tnode.before(span);
tnode.text("");
}
}
}
}
@Override
public void tail(Node node, int depth) {
}
}, document);
@Override
public void tail(Node node, int depth) {
}
}, document);
}
// Selective new lines
for (Element div : document.select("div"))

Loading…
Cancel
Save