优化链接分割规则,避免附加参数中存在 ,{ 时导致规则切错

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

格式化图片和匹配图片规则不在使用同一个正则,加快图片处理速度。

优化一下不需要循环执行却被循环执行的操作
pull/1123/head
bushixuanqi 3 years ago
parent 4290ad8fd1
commit fc2e37d113
  1. 9
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  2. 14
      app/src/main/java/io/legado/app/utils/HtmlFormatter.kt

@ -111,9 +111,11 @@ object ChapterProvider {
)
}
} else if (book.getImageStyle() != Book.imgStyleText) {
content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n")
.split("\n").forEach { text ->
if (text.isNotBlank()) {
var contentX = content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n").split("\n")
val start = contentX.first() == "\n"
val end = contentX.last() == "\n"
if(start || end )contentX = contentX.subList(if(start) 1 else 0,if(end) contentX.size-1 else contentX.size )
contentX.forEach { text ->
if (!text.startsWith("<img src=\"")) { //非图片
val isTitle = index == 0
val textPaint = if (isTitle) titlePaint else contentPaint
@ -132,7 +134,6 @@ object ChapterProvider {
}
}
}
}
textPages.last().height = durY + 20.dp
textPages.last().text = stringBuilder.toString()
textPages.forEachIndexed { index, item ->

@ -59,16 +59,17 @@ object HtmlFormatter {
do{
val url = matcher.group(1)!!
val pos = url.indexOf(',')
sb.append(keepImgHtml.substring(appendPos, matcher.start()).replace("\n","\n  ")) //非图片部分换行缩减
val urlBefore = url.substringBefore(',')
val beforeStr = keepImgHtml.substring(appendPos, matcher.start())
sb.append( if(beforeStr == "\n") '\n' else beforeStr.replace("\n","\n  ") ) //缩进换行下个非图片段落
sb.append(
"<img src=\"${
NetworkUtils.getAbsoluteURL(
redirectUrl,
url.substring(0, pos)
urlBefore
)
},${
url.substring(pos + 1 )
}${
url.substring(urlBefore.length)
}\">"
)
appendPos = matcher.end()
@ -78,7 +79,8 @@ object HtmlFormatter {
}
if (appendPos < keepImgHtml.length) {
sb.append(keepImgHtml.substring(appendPos, keepImgHtml.length).replace("\n","\n  ")) //非图片部分换行缩减
val beforeStr = keepImgHtml.substring(appendPos, keepImgHtml.length)
sb.append( if(beforeStr == "\n") '\n' else beforeStr.replace("\n","\n  ") ) //缩进换行下个非图片段落
}
return sb.toString()
}

Loading…
Cancel
Save