Merge pull request #1133 from bushixuanqi/master

图片链接里面有“{”也补全成绝对链接
pull/1135/head^2
kunfei 3 years ago committed by GitHub
commit 447a105405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/src/main/java/io/legado/app/utils/HtmlFormatter.kt

@ -32,7 +32,7 @@ object HtmlFormatter {
var hasMatch = true //普通图片标签是否还未处理过
var hasMatchX = false //是否存在带参数或带数据属性的图片标签
var pos = -1
val list = listOf("<img[^>]*src *= *\"([^\"{]+\\{(?:[^{}]|\\{[^}]+\\})+\\})\"[^>]*>","<img[^>]*data-[^=]*= *\"([^\"]+)\"[^>]*>","<img[^>]*src *= *\"([^\"]+)\"[^>]*>") //优先匹配用户处理过所以带参数的图片标签,其次匹配带数据属性的图片标签
val list = listOf("<img[^>]*src *= *\"([^\"{]*\\{(?:[^{}]|\\{[^}]+\\})+\\})\"[^>]*>","<img[^>]*data-[^=]*= *\"([^\"]*)\"[^>]*>","<img[^>]*src *= *\"([^\"]*)\"[^>]*>") //优先匹配用户处理过所以带参数的图片标签,其次匹配带数据属性的图片标签
while(++pos<3){
if(pos == 2) {
if(hasMatchX)break //普通图片标签只在不存在存在带参数或带数据属性的图片标签的时候匹配
@ -48,7 +48,7 @@ object HtmlFormatter {
if (hasMatch) { //格式化不带参数和数据属性的普通图片标签
var appendPos0 = 0
val matcher0 = Pattern.compile("<img[^>]*src *= *\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE).matcher(strBefore) //格式化普通图片标签
val matcher0 = Pattern.compile("<img[^>]*src *= *\"([^\"]*)\"[^>]*>", Pattern.CASE_INSENSITIVE).matcher(strBefore) //格式化普通图片标签
while (matcher0.find()) {
sb.append(strBefore.substring(appendPos0, matcher0.start()),"<img src=\"${NetworkUtils.getAbsoluteURL(redirectUrl,matcher0.group(1)!!)}\">")
appendPos0 = matcher0.end()
@ -61,7 +61,7 @@ object HtmlFormatter {
val url = matcher.group(1)!!
val urlMatcher = AnalyzeUrl.paramPattern.matcher(url)
if(urlMatcher.find()) NetworkUtils.getAbsoluteURL(redirectUrl,url.substring(0,urlMatcher.start())) + ',' + url.substring(urlMatcher.end())
else url
else NetworkUtils.getAbsoluteURL(redirectUrl,url)
}else NetworkUtils.getAbsoluteURL(redirectUrl,matcher.group(1)!!)
}\">")
@ -83,7 +83,7 @@ object HtmlFormatter {
var appendPos0 = 0
val strBefore = keepImgHtml.substring(endPos, keepImgHtml.length)
val matcher0 =
Pattern.compile("<img[^>]*src *= *\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE)
Pattern.compile("<img[^>]*src *= *\"([^\"]*)\"[^>]*>", Pattern.CASE_INSENSITIVE)
.matcher(strBefore) //格式化普通图片标签
while (matcher0.find()) {
str.append(strBefore.substring(appendPos0, matcher0.start()),"<img src=\"${ NetworkUtils.getAbsoluteURL( redirectUrl, matcher0.group(1)!! ) }\">")

Loading…
Cancel
Save