From d8adac1af190f1b0493789a01b9b9a9c6d9e57ed Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 2 Jan 2022 22:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96html=E6=97=B6?= =?UTF-8?q?=E5=8E=BB=E9=99=A4   =E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/utils/HtmlFormatter.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 ed2edd891..ad374c857 100644 --- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt +++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt @@ -6,6 +6,9 @@ import java.util.regex.Pattern @Suppress("RegExpRedundantEscape") object HtmlFormatter { + private val nbspRegex = "( )+".toRegex() + private val espRegex = "( | )".toRegex() + private val noPrintRegex = "( |‌|‍)".toRegex() private val wrapHtmlRegex = "]*>".toRegex() private val commentRegex = "".toRegex() //注释 private val notImgHtmlRegex = "])[^<>]*>".toRegex() @@ -17,7 +20,10 @@ object HtmlFormatter { fun format(html: String?, otherRegex: Regex = otherHtmlRegex): String { html ?: return "" - return html.replace(wrapHtmlRegex, "\n") + return html.replace(nbspRegex, " ") + .replace(espRegex, " ") + .replace(noPrintRegex, "") + .replace(wrapHtmlRegex, "\n") .replace(commentRegex, "") .replace(otherRegex, "") .replace("\\s*\\n+\\s*".toRegex(), "\n  ")