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

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

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

优化一下不需要循环执行却被循环执行的操作
pull/1123/head
bushixuanqi 3 years ago
parent 4290ad8fd1
commit fc2e37d113
  1. 37
      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,26 +111,27 @@ object ChapterProvider {
) )
} }
} else if (book.getImageStyle() != Book.imgStyleText) { } else if (book.getImageStyle() != Book.imgStyleText) {
content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n") var contentX = content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n").split("\n")
.split("\n").forEach { text -> val start = contentX.first() == "\n"
if (text.isNotBlank()) { val end = contentX.last() == "\n"
if (!text.startsWith("<img src=\"")) { //非图片 if(start || end )contentX = contentX.subList(if(start) 1 else 0,if(end) contentX.size-1 else contentX.size )
val isTitle = index == 0 contentX.forEach { text ->
val textPaint = if (isTitle) titlePaint else contentPaint if (!text.startsWith("<img src=\"")) { //非图片
if (!(isTitle && ReadBookConfig.titleMode == 2)) { val isTitle = index == 0
durY = setTypeText( val textPaint = if (isTitle) titlePaint else contentPaint
text, durY, textPages, if (!(isTitle && ReadBookConfig.titleMode == 2)) {
stringBuilder, isTitle, textPaint durY = setTypeText(
) text, durY, textPages,
} stringBuilder, isTitle, textPaint
} else { //图片 )
durY = setTypeImage(
book, bookChapter, text.substring(10, text.length-2),
durY, textPages, book.getImageStyle()
)
}
} }
} else { //图片
durY = setTypeImage(
book, bookChapter, text.substring(10, text.length-2),
durY, textPages, book.getImageStyle()
)
} }
}
} }
} }
textPages.last().height = durY + 20.dp textPages.last().height = durY + 20.dp

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

Loading…
Cancel
Save