From 0b0ca0c6cf51f241d30990f0b68ad85802c5e75f Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 15 Jun 2021 09:09:33 +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 --- app/src/main/assets/updateLog.md | 4 ++++ .../java/io/legado/app/utils/HtmlFormatter.kt | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 989c3b244..291a32ef1 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -8,6 +8,10 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则出现问题。先关闭替换净化并刷新,再观察是否正常。如果正常说明净化规则存在误杀,如果关闭后仍然出现相关问题,请点击源链接查看原文与正文是否相同,如果不同,再进行反馈。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2021/06/15** +* 添加配置导入文件规则功能 by bushixuanqi +* 文件夹分组样式优化(未完成) + **2021/06/06** * 添加自定义导出文件名 * 添加书架文件夹分组样式,未完成 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 fd3c6c269..2f4e126dc 100644 --- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt +++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt @@ -1,8 +1,8 @@ package io.legado.app.utils +import io.legado.app.constant.AppPattern import io.legado.app.model.analyzeRule.AnalyzeUrl import java.net.URL -import io.legado.app.constant.AppPattern object HtmlFormatter { private val wrapHtmlRegex = "]*>".toRegex() @@ -22,22 +22,23 @@ object HtmlFormatter { fun formatKeepImg(html: String?, redirectUrl: URL?): String { html ?: return "" - var formatHtml = formatKeepImg(html) val sb = StringBuffer() - val matcher = AppPattern.imgPattern.matcher(formatHtml) + val matcher = AppPattern.imgPattern.matcher(html) + var appendPos = 0 while (matcher.find()) { val urlArray = matcher.group(1)!!.split(AnalyzeUrl.splitUrlRegex) var url = NetworkUtils.getAbsoluteURL(redirectUrl, urlArray[0]) if (urlArray.size > 1) { url = "$url,${urlArray[1]}" } - //将Matcher上次匹配结尾到本次匹配结尾这段字符串序列追加到sb中,且是先将其中匹配到的部分替换后再追加 - matcher.appendReplacement(sb, "") + sb.append(html.substring(appendPos, matcher.start())) + sb.append("") + appendPos = matcher.end() } - //将Matcher最后那个匹配之后的字串匹配到追加到sb中 - matcher.appendTail(sb) - - return sb.toString() + if (appendPos < html.length) { + sb.append(html.substring(appendPos, html.length)) + } + return formatKeepImg(sb.toString()) } }