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

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

优化格式化图片标签操作和匹配图片标签操作,加快图片处理速度
pull/1118/head
bushixuanqi 3 years ago
parent 715797c69c
commit 6c0b7dcbf4
  1. 2
      app/src/main/java/io/legado/app/constant/AppPattern.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt

@ -9,7 +9,7 @@ object AppPattern {
val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}") val EXP_PATTERN: Pattern = Pattern.compile("\\{\\{([\\w\\W]*?)\\}\\}")
//只匹配格式化后的图片 //只匹配格式化后的图片
val imgPattern: Pattern = Pattern.compile("<img src=\"([^\"{]+(?:\\{(?:[^{}]|\\{[^{}]*\\})*\\})?)\">") val imgPattern: Pattern = Pattern.compile("<img src=\"([^\"{]+(?:\\{(?:[^{}]|\\{[^{}]*\\})*\\})?)\" >")
val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著") val nameRegex = Regex("\\s+作\\s*者.*|\\s+\\S+\\s+著")
val authorRegex = Regex("^.*?作\\s*者[::\\s]*|\\s+著") val authorRegex = Regex("^.*?作\\s*者[::\\s]*|\\s+著")

@ -111,10 +111,10 @@ object ChapterProvider {
) )
} }
} else { } else {
content.replace(AppPattern.imgPattern.toRegex(), "\n\b\$0\n") content.replace(AppPattern.imgPattern.toRegex(), "\n\$0\n")
.split("\n").forEach { text -> .split("\n").forEach { text ->
if (text.isNotBlank()) { if (text.isNotBlank()) {
if(text[0] != '\b'){ //非图片 if(!text.startsWith("<img src=\"")){ //非图片
val isTitle = index == 0 val isTitle = index == 0
val textPaint = if (isTitle) titlePaint else contentPaint val textPaint = if (isTitle) titlePaint else contentPaint
if (!(isTitle && ReadBookConfig.titleMode == 2)) { if (!(isTitle && ReadBookConfig.titleMode == 2)) {
@ -125,7 +125,7 @@ object ChapterProvider {
} }
} else { //图片 } else { //图片
durY = setTypeImage( durY = setTypeImage(
book, bookChapter, text.substring(1), book, bookChapter, text,
durY, textPages, book.getImageStyle() durY, textPages, book.getImageStyle()
) )
} }

Loading…
Cancel
Save