From c163d2e087feb910063cc47a27201c32af146c82 Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 20:19:38 +0800
Subject: [PATCH 1/5] Update HtmlFormatter.kt
---
.../java/io/legado/app/utils/HtmlFormatter.kt | 52 +++++--------------
1 file changed, 14 insertions(+), 38 deletions(-)
diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
index 2fa883f4d..46789b13b 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -24,8 +24,7 @@ object HtmlFormatter {
html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
.replace(notImgHtmlRegex, "")
- .replace("[\\n\\s]+\$|^[\\n\\s]+".toRegex(), "")
- .replace("\\s*\\n+\\s*".toRegex(), "\n")
+ .replace("\\n\\s*\\n".toRegex(), "\n")
var str = StringBuffer()
var endPos = 0
@@ -50,28 +49,20 @@ object HtmlFormatter {
var appendPos0 = 0
val matcher0 = Pattern.compile("]*src *= *\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE).matcher(strBefore) //格式化普通图片标签
while (matcher0.find()) {
- val strBefore0 = strBefore.substring(appendPos0, matcher0.start())
- sb.append( if (strBefore0.isBlank()) strBefore0 else strBefore0.replace("\n","\n "))
- sb.append("")
+ sb.append(strBefore.substring(appendPos0, matcher0.start()),"")
appendPos0 = matcher0.end()
}
- strBefore = if (appendPos0 < strBefore.length) strBefore.substring(appendPos0, strBefore.length) else ""
+ strBefore = strBefore.substring(appendPos0, strBefore.length)
}
- sb.append(
- if (strBefore.isBlank()) strBefore else strBefore.replace("\n","\n ") //缩进图片之间的非空白段落
- )
-
- if (pos == 0) {
- val url = matcher.group(1)!!
- val urlMatcher = AnalyzeUrl.paramPattern.matcher(url)
- val find = urlMatcher.find()
- sb.append("")
-
- } else sb.append("")
+ }else NetworkUtils.getAbsoluteURL(redirectUrl,matcher.group(1)!!)
+ }\">")
appendPos = matcher.end()
} while (matcher.find())
@@ -86,7 +77,7 @@ object HtmlFormatter {
}
if (endPos < keepImgHtml.length) {
- str.append( (
+ str.append(
if(hasMatchX){ //处理末尾的普通图片标签
var appendPos0 = 0
val strBefore = keepImgHtml.substring(endPos, keepImgHtml.length)
@@ -94,28 +85,13 @@ object HtmlFormatter {
Pattern.compile("]*src *= *\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE)
.matcher(strBefore) //格式化普通图片标签
while (matcher0.find()) {
- val strBefore0 = strBefore.substring(appendPos0, matcher0.start())
- str.append(
- if (strBefore0.isBlank()) strBefore0 else strBefore0.replace(
- "\n",
- "\n "
- )
- )
- str.append(
- ""
- )
+ str.append(strBefore.substring(appendPos0, matcher0.start()),"")
appendPos0 = matcher0.end()
}
- if (appendPos0 < strBefore.length) strBefore.substring( appendPos0, strBefore.length ) else ""
+ strBefore.substring( appendPos0, strBefore.length )
}else keepImgHtml.substring( endPos, keepImgHtml.length )
- ).replace("\n","\n ") ) //缩进图片之后的非空白段落
+ ) //缩进图片之后的非空白段落
}
-
return str.toString()
}
}
From 633c5129febeac4bafcc66b945c18a282bf68716 Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 20:22:28 +0800
Subject: [PATCH 2/5] Update HtmlFormatter.kt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化
---
app/src/main/java/io/legado/app/utils/HtmlFormatter.kt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
index 46789b13b..325eefdf0 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -24,7 +24,7 @@ object HtmlFormatter {
html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
.replace(notImgHtmlRegex, "")
- .replace("\\n\\s*\\n".toRegex(), "\n")
+ .replace("\\n\\s*\\n|\\n$|^\\n".toRegex(), "\n")
var str = StringBuffer()
var endPos = 0
From 7cdf7b602d9387581fd7f1447043c3b089a2a1aa Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 20:24:46 +0800
Subject: [PATCH 3/5] Update HtmlFormatter.kt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化
---
app/src/main/java/io/legado/app/utils/HtmlFormatter.kt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
index 325eefdf0..990422fa8 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -24,7 +24,7 @@ object HtmlFormatter {
html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
.replace(notImgHtmlRegex, "")
- .replace("\\n\\s*\\n|\\n$|^\\n".toRegex(), "\n")
+ .replace("\\n\\s*\\n|\\n\\s*$|^\\s*\\n".toRegex(), "\n")
var str = StringBuffer()
var endPos = 0
From a0e0dfd9eab567902f36b4bb315770e02a0367a3 Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 20:35:29 +0800
Subject: [PATCH 4/5] Update HtmlFormatter.kt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化
---
app/src/main/java/io/legado/app/utils/HtmlFormatter.kt | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
index 990422fa8..65ed42b80 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -24,6 +24,7 @@ object HtmlFormatter {
html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
.replace(notImgHtmlRegex, "")
+ .replace("\\n\\s*$|^\\s*\\n".toRegex(), "")
.replace("\\n\\s*\\n|\\n\\s*$|^\\s*\\n".toRegex(), "\n")
var str = StringBuffer()
From 1378ce67bfd791d33aa945d1e8cd111a58b01943 Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 20:36:28 +0800
Subject: [PATCH 5/5] Update HtmlFormatter.kt
---
app/src/main/java/io/legado/app/utils/HtmlFormatter.kt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
index 65ed42b80..96dbf045b 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -25,7 +25,7 @@ object HtmlFormatter {
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
.replace(notImgHtmlRegex, "")
.replace("\\n\\s*$|^\\s*\\n".toRegex(), "")
- .replace("\\n\\s*\\n|\\n\\s*$|^\\s*\\n".toRegex(), "\n")
+ .replace("\\n\\s*\\n".toRegex(), "\n")
var str = StringBuffer()
var endPos = 0