优化链接分割规则,避免 ,{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. 41
      app/src/main/java/io/legado/app/utils/HtmlFormatter.kt

@ -61,7 +61,14 @@ data class BookChapter(
return false 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)) fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title))

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

Loading…
Cancel
Save