From c80afa50c5d1b46a7552f3a85e708bd172ee79c4 Mon Sep 17 00:00:00 2001 From: bushixuanqi <2208877960@qq.com> Date: Tue, 13 Jul 2021 02:02:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=93=BE=E6=8E=A5=E5=88=86?= =?UTF-8?q?=E5=89=B2=E8=A7=84=E5=88=99=EF=BC=8C=E9=81=BF=E5=85=8D=20,{c?= =?UTF-8?q?=E5=8F=82=E6=95=B0}=20=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E4=B8=AD=E4=B9=9F=E5=AD=98=E5=9C=A8=20,{=20=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=A7=84=E5=88=99=E5=88=87=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复这种页数列表写法中,js部分内含 < 或 > 就会切割错误的问题 优化格式化图片标签操作和匹配图片标签操作,加快图片处理速度 --- .../legado/app/data/entities/BookChapter.kt | 9 +++- .../java/io/legado/app/utils/HtmlFormatter.kt | 45 ++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 6162779cb..67bba2e5d 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -61,7 +61,14 @@ data class BookChapter( return false } - fun getAbsoluteURL() = url.replace("^\\s*([^,\\s]+)\\s*".toRegex()){ NetworkUtils.getAbsoluteURL(baseUrl,it.groupValues[1]) } + fun getAbsoluteURL():String{ + val pos = url.indexOf(',') + return if(pos == -1) NetworkUtils.getAbsoluteURL(baseUrl,url) + else NetworkUtils.getAbsoluteURL( + baseUrl, + url.substring(0, pos) + ) + url.substring(pos) + } fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title)) 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 9370e44d6..fd1d6894e 100644 --- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt +++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt @@ -32,15 +32,48 @@ object HtmlFormatter { val matcher = imgPattern.matcher(keepImgHtml) var appendPos = 0 - while (matcher.find()) { + + if(matcher.find()){ + var url = matcher.group(1)!! + var pos = url.indexOf(',') sb.append(keepImgHtml.substring(appendPos, matcher.start())) - sb.append("") + sb.append( + "" + ) appendPos = matcher.end() + if(pos == -1) { + while (matcher.find()) { + sb.append(keepImgHtml.substring(appendPos, matcher.start())) + sb.append( "" ) + appendPos = matcher.end() + } + }else{ + while (matcher.find()) { + url = matcher.group(1)!! + pos = url.indexOf(',') + sb.append(keepImgHtml.substring(appendPos, matcher.start())) + sb.append( + "" + ) + appendPos = matcher.end() + } + } } + if (appendPos < keepImgHtml.length) { sb.append(keepImgHtml.substring(appendPos, keepImgHtml.length)) }