优化链接分割规则,避免 ,{c参数} 的字符串中也存在 ,{ ,导致规则切错

修复<str0,str2,...{{js}}>这种页数列表写法中,js部分内含 < 或 > 就会切割错误的问题

优化格式化图片标签操作和匹配图片标签操作,加快图片处理速度
pull/1118/head
bushixuanqi 3 years ago
parent 9812a01349
commit c80afa50c5
  1. 9
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  2. 45
      app/src/main/java/io/legado/app/utils/HtmlFormatter.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))

@ -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("<img src=\"${
matcher.group(1)!!.replace("^\\s*([^,\\s]+)\\s*".toRegex()){
NetworkUtils.getAbsoluteURL(redirectUrl,it.groupValues[1])
}
}\">")
sb.append(
"<img src=\"${
if (pos == -1) url else NetworkUtils.getAbsoluteURL(
redirectUrl,
url.substring(0, pos)
) + url.substring(pos)
}\">"
)
appendPos = matcher.end()
if(pos == -1) {
while (matcher.find()) {
sb.append(keepImgHtml.substring(appendPos, matcher.start()))
sb.append( "<img src=\"${
NetworkUtils.getAbsoluteURL(redirectUrl,matcher.group(1)!!)
}\">" )
appendPos = matcher.end()
}
}else{
while (matcher.find()) {
url = matcher.group(1)!!
pos = url.indexOf(',')
sb.append(keepImgHtml.substring(appendPos, matcher.start()))
sb.append(
"<img src=\"${
NetworkUtils.getAbsoluteURL(
redirectUrl,
url.substring(0, pos)
)
}${
url.substring(pos)
}\">"
)
appendPos = matcher.end()
}
}
}
if (appendPos < keepImgHtml.length) {
sb.append(keepImgHtml.substring(appendPos, keepImgHtml.length))
}

Loading…
Cancel
Save