Update HtmlFormatter.kt

优化
pull/1123/head
bushixuanqi 3 years ago committed by GitHub
parent 0c5c7e06b8
commit 2312e24f0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/src/main/java/io/legado/app/utils/HtmlFormatter.kt

@ -44,20 +44,7 @@ object HtmlFormatter {
val matcher = imgPattern.matcher(keepImgHtml) val matcher = imgPattern.matcher(keepImgHtml)
var appendPos = 0 var appendPos = 0
if(matcher.find()){ while(matcher.find()){
if(hasDataType || matcher.group(1)!!.indexOf(',') == -1) { //图片无参
do{
sb.append(keepImgHtml.substring(appendPos, matcher.start()).replace("\n","\n  ")) //非图片部分换行缩进
sb.append( "<img src=\"${
NetworkUtils.getAbsoluteURL(redirectUrl,matcher.group(1)!!)
}\">" )
appendPos = matcher.end()
}while (matcher.find())
}else{ //图片有参
do{
val url = matcher.group(1)!! val url = matcher.group(1)!!
val urlBefore = url.substringBefore(',') val urlBefore = url.substringBefore(',')
sb.append( keepImgHtml.substring(appendPos, matcher.start()).replace("\n","\n  ") ) //缩进换行下个非图片段落 sb.append( keepImgHtml.substring(appendPos, matcher.start()).replace("\n","\n  ") ) //缩进换行下个非图片段落
@ -72,9 +59,6 @@ object HtmlFormatter {
}\">" }\">"
) )
appendPos = matcher.end() appendPos = matcher.end()
}while(matcher.find())
}
} }
if (appendPos < keepImgHtml.length) { if (appendPos < keepImgHtml.length) {

Loading…
Cancel
Save