htmlFormat恢复原来的

pull/1155/head
gedoor 3 years ago
parent db1fc2ee19
commit bfb6ee869e
  1. 13
      app/src/main/java/io/legado/app/utils/HtmlFormatter.kt

@ -22,14 +22,10 @@ object HtmlFormatter {
.replace("[\\n\\s]+$".toRegex(), "") .replace("[\\n\\s]+$".toRegex(), "")
} }
fun formatKeepImg(html: String?) = format(html, notImgHtmlRegex) fun formatKeepImg(html: String?, redirectUrl: URL? = null): String {
fun formatKeepImg(html: String?, redirectUrl: URL?): String {
html ?: return "" html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n") val keepImgHtml = format(html, notImgHtmlRegex)
.replace(notImgHtmlRegex, "")
.replace("\\n\\s*$|^\\s*\\n".toRegex(), "")
.replace("\\n\\s*\\n".toRegex(), "\n")
//正则的“|”处于顶端而不处于()中时,具有类似||的熔断效果,故以此机制简化原来的代码 //正则的“|”处于顶端而不处于()中时,具有类似||的熔断效果,故以此机制简化原来的代码
val matcher = formatImagePattern.matcher(keepImgHtml) val matcher = formatImagePattern.matcher(keepImgHtml)
var appendPos = 0 var appendPos = 0
@ -38,7 +34,8 @@ object HtmlFormatter {
var param = "" var param = ""
sb.append( sb.append(
keepImgHtml.substring(appendPos, matcher.start()), "<img src=\"${ keepImgHtml.substring(appendPos, matcher.start()), "<img src=\"${
NetworkUtils.getAbsoluteURL(redirectUrl, NetworkUtils.getAbsoluteURL(
redirectUrl,
matcher.group(1)?.let { matcher.group(1)?.let {
val urlMatcher = AnalyzeUrl.paramPattern.matcher(it) val urlMatcher = AnalyzeUrl.paramPattern.matcher(it)
if (urlMatcher.find()) { if (urlMatcher.find()) {

Loading…
Cancel
Save