From aff04860c57208886dd9c0a5bbd033cc73d6bc9a Mon Sep 17 00:00:00 2001 From: bushixuanqi <2208877960@qq.com> Date: Sun, 18 Jul 2021 13:46:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/utils/HtmlFormatter.kt | 16 ++++++++-------- 1 file changed, 8 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 ac494f8f4..1cce40e9c 100644 --- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt +++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt @@ -11,10 +11,10 @@ object HtmlFormatter { fun format(html: String?, otherRegex: Regex = otherHtmlRegex): String { html ?: return "" return html.replace(wrapHtmlRegex, "\n") - .replace(otherRegex, "") - .replace("\\s*\\n+\\s*".toRegex(), "\n  ") - .replace("^[\\n\\s]+".toRegex(), "  ") - .replace("[\\n\\s]+$".toRegex(), "") + .replace(otherRegex, "") + .replace("\\s*\\n+\\s*".toRegex(), "\n  ") + .replace("^[\\n\\s]+".toRegex(), "  ") + .replace("[\\n\\s]+$".toRegex(), "") } fun formatKeepImg(html: String?) = format(html, notImgHtmlRegex) @@ -22,9 +22,9 @@ object HtmlFormatter { fun formatKeepImg(html: String?, redirectUrl: URL?): String { html ?: return "" val keepImgHtml = html.replace(wrapHtmlRegex, "\n") - .replace(notImgHtmlRegex, "") - .replace("[\\n\\s]+\$|^[\\n\\s]*".toRegex(), "") - .replace("\\s*\\n+\\s*".toRegex(), "\n") + .replace(notImgHtmlRegex, "") + .replace("[\\n\\s]+\$|^[\\n\\s]*".toRegex(), "") + .replace("\\s*\\n+\\s*".toRegex(), "\n") val sb = StringBuffer() var endPos = 0 @@ -36,7 +36,7 @@ object HtmlFormatter { val urlBefore = url.substringBefore(',') val strBefore = keepImgHtml.substring(appendPos, matcher.start()) sb.append( - if(strBefore.isBlank()) strBefore else strBefore.replace("\n", "\n  ") //缩进图片之间的非空白段落 + if(strBefore.isBlank()) '\n' else strBefore.replace("\n", "\n  ") //缩进图片之间的非空白段落 ) sb.append( "