|
|
@ -31,11 +31,16 @@ object HtmlFormatter { |
|
|
|
html ?: return "" |
|
|
|
html ?: return "" |
|
|
|
val sb = StringBuffer() |
|
|
|
val sb = StringBuffer() |
|
|
|
val matcher = imgPattern.matcher(html) |
|
|
|
val matcher = imgPattern.matcher(html) |
|
|
|
|
|
|
|
var appendPos = 0 |
|
|
|
while (matcher.find()) { |
|
|
|
while (matcher.find()) { |
|
|
|
val url = NetworkUtils.getAbsoluteURL(redirectUrl, matcher.group(1)!!) |
|
|
|
val url = NetworkUtils.getAbsoluteURL(redirectUrl, matcher.group(1)!!) |
|
|
|
matcher.appendReplacement(sb, "<img src=\"$url\" >") |
|
|
|
sb.append(html.substring(appendPos, matcher.start())) |
|
|
|
|
|
|
|
sb.append("<img src=\"$url\" >") |
|
|
|
|
|
|
|
appendPos = matcher.end() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (appendPos < html.length) { |
|
|
|
|
|
|
|
sb.append(html.substring(appendPos, html.length)) |
|
|
|
} |
|
|
|
} |
|
|
|
matcher.appendTail(sb) |
|
|
|
|
|
|
|
return sb.replace(wrapHtmlRegex, "\n") |
|
|
|
return sb.replace(wrapHtmlRegex, "\n") |
|
|
|
.replace(notImgHtmlRegex, "") |
|
|
|
.replace(notImgHtmlRegex, "") |
|
|
|
.replace("\\s*\\n+\\s*".toRegex(), "\n ") |
|
|
|
.replace("\\s*\\n+\\s*".toRegex(), "\n ") |
|
|
|