pull/909/head
gedoor 4 years ago
parent 05fecb34bf
commit df842939f6
  1. 6
      app/src/main/java/io/legado/app/utils/HtmlFormatter.kt

@ -7,7 +7,7 @@ object HtmlFormatter {
private val wrapHtmlRegex = "</?(?:div|p|br|hr|h\\d|article|dd|dl)[^>]*>".toRegex() private val wrapHtmlRegex = "</?(?:div|p|br|hr|h\\d|article|dd|dl)[^>]*>".toRegex()
private val notImgHtmlRegex = "</?(?!img)[a-zA-Z]+(?=[ >])[^<>]*>".toRegex() private val notImgHtmlRegex = "</?(?!img)[a-zA-Z]+(?=[ >])[^<>]*>".toRegex()
private val otherHtmlRegex = "</?[a-zA-Z]+(?=[ >])[^<>]*>".toRegex() private val otherHtmlRegex = "</?[a-zA-Z]+(?=[ >])[^<>]*>".toRegex()
private val imgPattern = Pattern.compile("(<img )[^>]*src=\"([^\"]+)\"[^>]*(>)") private val imgPattern = Pattern.compile("<img [^>]*src=.*?\"(.*?(?:,\\{.*\\})?)\".*?>")
fun format(html: String?): String { fun format(html: String?): String {
html ?: return "" html ?: return ""
@ -32,8 +32,8 @@ object HtmlFormatter {
val sb = StringBuffer() val sb = StringBuffer()
val matcher = imgPattern.matcher(html) val matcher = imgPattern.matcher(html)
while (matcher.find()) { while (matcher.find()) {
val url = NetworkUtils.getAbsoluteURL(redirectUrl, matcher.group(2)!!) val url = NetworkUtils.getAbsoluteURL(redirectUrl, matcher.group(1)!!)
matcher.appendReplacement(sb, "${matcher.group(1)} src=\"$url\"${matcher.group(3)}") matcher.appendReplacement(sb, "<img src=\"$url\" >")
} }
matcher.appendTail(sb) matcher.appendTail(sb)
return sb.replace(wrapHtmlRegex, "\n") return sb.replace(wrapHtmlRegex, "\n")

Loading…
Cancel
Save