From bfb6ee869e03242ec92b4c9120069c8d78123026 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 19 Jul 2021 22:42:22 +0800 Subject: [PATCH] =?UTF-8?q?htmlFormat=E6=81=A2=E5=A4=8D=E5=8E=9F=E6=9D=A5?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/utils/HtmlFormatter.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt index cae9b2251..52763a41f 100644 --- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt +++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt @@ -22,14 +22,10 @@ object HtmlFormatter { .replace("[\\n\\s]+$".toRegex(), "") } - fun formatKeepImg(html: String?) = format(html, notImgHtmlRegex) - - fun formatKeepImg(html: String?, redirectUrl: URL?): String { + fun formatKeepImg(html: String?, redirectUrl: URL? = null): String { html ?: return "" - val keepImgHtml = html.replace(wrapHtmlRegex, "\n") - .replace(notImgHtmlRegex, "") - .replace("\\n\\s*$|^\\s*\\n".toRegex(), "") - .replace("\\n\\s*\\n".toRegex(), "\n") + val keepImgHtml = format(html, notImgHtmlRegex) + //正则的“|”处于顶端而不处于()中时,具有类似||的熔断效果,故以此机制简化原来的代码 val matcher = formatImagePattern.matcher(keepImgHtml) var appendPos = 0 @@ -38,7 +34,8 @@ object HtmlFormatter { var param = "" sb.append( keepImgHtml.substring(appendPos, matcher.start()), "