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()), "