Added workaround for links between parenthesis

This commit is contained in:
M66B 2020-07-17 10:02:42 +02:00
parent 0c9e85caf9
commit c355ca8981
1 changed files with 18 additions and 8 deletions

View File

@ -905,25 +905,35 @@ public class HtmlHelper {
parent = parent.parent(); parent = parent.parent();
} }
boolean email = matcher.group().contains("@") && !matcher.group().contains(":"); String group = matcher.group();
Log.d("Web url=" + matcher.group() + int start = matcher.start();
" " + matcher.start() + "..." + matcher.end() + "/" + text.length() + int end = matcher.end();
// Workaround for links between parenthesis
if (group.endsWith(")") &&
start > 0 && text.charAt(start - 1) == '(') {
group = group.substring(0, group.length() - 1);
end--;
}
boolean email = group.contains("@") && !group.contains(":");
Log.d("Web url=" + group + " " + start + "..." + end + "/" + text.length() +
" linked=" + linked + " email=" + email + " count=" + links); " linked=" + linked + " email=" + email + " count=" + links);
if (linked) if (linked)
span.appendText(text.substring(pos, matcher.end())); span.appendText(text.substring(pos, end));
else { else {
span.appendText(text.substring(pos, matcher.start())); span.appendText(text.substring(pos, start));
Element a = document.createElement("a"); Element a = document.createElement("a");
a.attr("href", (email ? "mailto:" : "") + matcher.group()); a.attr("href", (email ? "mailto:" : "") + group);
a.text(matcher.group()); a.text(group);
span.appendChild(a); span.appendChild(a);
links++; links++;
} }
pos = matcher.end(); pos = end;
} while (links < MAX_AUTO_LINK && matcher.find()); } while (links < MAX_AUTO_LINK && matcher.find());
span.appendText(text.substring(pos)); span.appendText(text.substring(pos));