From cfca8facbe49f361202d05d1d138b6f3ee4f85ad Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Thu, 15 Oct 2020 01:49:53 +0200 Subject: [PATCH] Use '%23' instead of '#' when rendering #hashtag style text from markdown --- .../browser/ui/findcontent/FileViewFragment.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index de9ce019..bc66d751 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -92,6 +92,8 @@ import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import io.lbry.browser.MainActivity; import io.lbry.browser.R; @@ -2072,7 +2074,17 @@ public class FileViewFragment extends BaseFragment implements @Override public void onSuccess(String text) { String html = buildMarkdownHtml(text); + if (webView != null) { + // Due to a change to Chrome, WebView only displays '#' -and everything after it- + // if it is '%23' instead. Problem appears in text like '#2' or #hashtags. + Pattern pattern = Pattern.compile("#(\\S+)"); + Matcher matcher = pattern.matcher(html); + + if (matcher.find()) { + html = html.replaceAll(pattern.toString(), "&%2335;" + matcher.group(1)); + } + webView.loadData(html, "text/html", "utf-8"); } }