I am using this code to highlight text in android webview.
public void highlight(int pageNumber) {
dbManager = new DBManager(webView.getContext());
dbManager.open();
cursor = dbManager.getSelectedID(books.get(0).getmDbId());
String quotesDb = cursor.getString(cursor.getColumnIndex("_quote"));
String currnetPage = cursor.getString(cursor.getColumnIndex("_current_page"));
List<String> myList = Arrays.asList(quotesDb.split("½_½"));
webView.evaluateJavascript("function doSearch(text, backgroundColor) {\n" +
" if (window.find && window.getSelection) {\n" +
" var windowHeight = window.scrollY;\n" +
" document.designMode = 'on';\n" +
" var sel = window.getSelection();\n" +
" sel.collapse(document.body, 0);\n" +
" while (window.find(text)) {\n" +
" document.execCommand('HiliteColor', false, backgroundColor);\n" +
" sel.collapseToEnd();\n" +
" }\n" +
" document.designMode = 'off';\n" +
" window.scrollTo(0, windowHeight);\n" +
" }\n" +
"}", null);
Log.e("SAVE_QUOTE ", "LIST_SIZE ----> " + myList.size());
if (pageNumber == Integer.parseInt(currnetPage)) {
for (int j = 0; j < myList.size(); j++) {
webView.evaluateJavascript("doSearch('" + myList.get(j) + "', 'SkyBlue')", null);
// webView.findAllAsync(myList.get(j));
}
}
}
Everything works fine until I select the code with a new line (paragraph). Then I get an error and the text is not highlighted.
/chromium: [INFO:CONSOLE(1)] "Uncaught SyntaxError: Invalid or unexpected token", source: file:///data/user/0/com.mms.tts/cache/W1/index.xhtml (1)