Remove diacrits before highlighting

pull/209/head
M66B 2 years ago
parent 57096d2b9f
commit 6db045cf0c

@ -111,6 +111,7 @@ import java.io.InputStream;
import java.io.StringReader; import java.io.StringReader;
import java.net.URI; import java.net.URI;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.Normalizer;
import java.text.ParseException; import java.text.ParseException;
import java.text.ParsePosition; import java.text.ParsePosition;
import java.util.ArrayList; import java.util.ArrayList;
@ -2937,6 +2938,10 @@ public class HtmlHelper {
static Document highlightSearched(Context context, Document document, String query) { static Document highlightSearched(Context context, Document document, String query) {
int color = Helper.resolveColor(context, R.attr.colorHighlight); int color = Helper.resolveColor(context, R.attr.colorHighlight);
query = Normalizer.normalize(query, Normalizer.Form.NFKD)
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
// TODO: fix highlighting pre processed text
List<String> word = new ArrayList<>(); List<String> word = new ArrayList<>();
List<String> plus = new ArrayList<>(); List<String> plus = new ArrayList<>();
@ -2960,24 +2965,28 @@ public class HtmlHelper {
if (node instanceof TextNode) if (node instanceof TextNode)
try { try {
TextNode tnode = (TextNode) node; TextNode tnode = (TextNode) node;
String text = tnode.getWholeText(); String text = Normalizer.normalize(tnode.getWholeText(), Normalizer.Form.NFKD)
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
Matcher result = p.matcher(text); Matcher result = p.matcher(text);
int prev = 0; int prev = 0;
Element holder = document.createElement("span"); Element holder = document.createElement("span");
while (result.find()) { while (result.find()) {
holder.appendText(text.substring(prev, result.start(1))); int start = result.start(1);
int end = result.end(1);
holder.appendText(text.substring(prev, start));
Element span = document.createElement("span"); Element span = document.createElement("span");
span.attr("style", mergeStyles( span.attr("style", mergeStyles(
span.attr("style"), span.attr("style"),
"font-size:larger; background-color:" + encodeWebColor(color) "font-size:larger; background-color:" + encodeWebColor(color)
)); ));
span.text(text.substring(result.start(1), result.end(1))); span.text(text.substring(start, end));
holder.appendChild(span); holder.appendChild(span);
prev = result.end(1); prev = end;
} }
if (prev == 0) // No matches if (prev == 0) // No matches

Loading…
Cancel
Save