From eb7c30e3d3b1b245e0cba9226b61a69a6bae8a49 Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 13:44:49 +0800
Subject: [PATCH 1/6] Update HtmlFormatter.kt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化
---
.../java/io/legado/app/utils/HtmlFormatter.kt | 21 ++++++++++---------
1 file changed, 11 insertions(+), 10 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 a15cbedcf..6a62fddfd 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -11,10 +11,10 @@ object HtmlFormatter {
fun format(html: String?, otherRegex: Regex = otherHtmlRegex): String {
html ?: return ""
return html.replace(wrapHtmlRegex, "\n")
- .replace(otherRegex, "")
- .replace("\\s*\\n+\\s*".toRegex(), "\n ")
- .replace("^[\\n\\s]+".toRegex(), " ")
- .replace("[\\n\\s]+$".toRegex(), "")
+ .replace(otherRegex, "")
+ .replace("\\s*\\n+\\s*".toRegex(), "\n ")
+ .replace("^[\\n\\s]+".toRegex(), " ")
+ .replace("[\\n\\s]+$".toRegex(), "")
}
fun formatKeepImg(html: String?) = format(html, notImgHtmlRegex)
@@ -22,9 +22,9 @@ object HtmlFormatter {
fun formatKeepImg(html: String?, redirectUrl: URL?): String {
html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
- .replace(notImgHtmlRegex, "")
- .replace("[\\n\\s]+\$|^[\\n\\s]*".toRegex(), "")
- .replace("\\s*\\n+\\s*".toRegex(), "\n")
+ .replace(notImgHtmlRegex, "")
+ .replace("[\\n\\s]+\$|^[\\n\\s]*".toRegex(), "")
+ .replace("\\s*\\n+\\s*".toRegex(), "\n")
val sb = StringBuffer()
var endPos = 0
@@ -34,9 +34,10 @@ object HtmlFormatter {
while (matcher.find()) {
val url = matcher.group(1)!!
val urlBefore = url.substringBefore(',')
+ val strBefore = keepImgHtml.substring(appendPos, matcher.start())
sb.append(
- keepImgHtml.substring(appendPos, matcher.start()).replace("\n", "\n ")
- ) //缩进换行下个非图片段落
+ if(strBefore.isBlank()) strBefore else strBefore.replace("\n", "\n ") //缩进图片之间的非空白段落
+ )
sb.append(
"
Date: Sun, 18 Jul 2021 13:46:32 +0800
Subject: [PATCH 2/6] 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 6a62fddfd..1cce40e9c 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -36,7 +36,7 @@ object HtmlFormatter {
val urlBefore = url.substringBefore(',')
val strBefore = keepImgHtml.substring(appendPos, matcher.start())
sb.append(
- if(strBefore.isBlank()) strBefore else strBefore.replace("\n", "\n ") //缩进图片之间的非空白段落
+ if(strBefore.isBlank()) '\n' else strBefore.replace("\n", "\n ") //缩进图片之间的非空白段落
)
sb.append(
"
Date: Sun, 18 Jul 2021 13:50:08 +0800
Subject: [PATCH 3/6] 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 1cce40e9c..fd1a67455 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -52,7 +52,7 @@ object HtmlFormatter {
}
if (endPos < keepImgHtml.length) {
- sb.append( keepImgHtml.substring( endPos, keepImgHtml.length ).replace("\n","\n ") ) //缩进图片之间的非空白段落
+ sb.append( keepImgHtml.substring( endPos, keepImgHtml.length ).replace("\n","\n ") ) //缩进图片之后的非空白段落
}
return sb.toString()
}
From bde448019041df85e6147a36784b44e733b70f43 Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 14:01:55 +0800
Subject: [PATCH 4/6] Update BookContent.kt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
恢复
---
.../main/java/io/legado/app/model/webBook/BookContent.kt | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt
index 618d06ad5..364fa06df 100644
--- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt
+++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt
@@ -52,7 +52,7 @@ object BookContent {
var contentData = analyzeContent(
book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl
)
- content.append(contentData.content)
+ content.append(contentData.content).append("\n")
if (contentData.nextUrl.size == 1) {
var nextUrl = contentData.nextUrl[0]
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
@@ -74,7 +74,7 @@ object BookContent {
)
nextUrl =
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
- content.append("\n").append(contentData.content)
+ content.append(contentData.content).append("\n")
}
}
Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
@@ -98,10 +98,11 @@ object BookContent {
}
asyncArray.forEach { coroutine ->
scope.ensureActive()
- content.append("\n").append(coroutine.await())
+ content.append(coroutine.await()).append("\n")
}
}
}
+ content.deleteCharAt(content.length - 1)
var contentStr = content.toString()
val replaceRegex = contentRule.replaceRegex
if (!replaceRegex.isNullOrEmpty()) {
@@ -149,4 +150,4 @@ object BookContent {
}
return ContentData(content, nextUrlList)
}
-}
\ No newline at end of file
+}
From 9bbcb6b64b03c36d309cc63dc05d1a24c267756a Mon Sep 17 00:00:00 2001
From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com>
Date: Sun, 18 Jul 2021 14:20:56 +0800
Subject: [PATCH 5/6] 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 | 4 ++--
1 file changed, 2 insertions(+), 2 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 fd1a67455..e1cedc005 100644
--- a/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
+++ b/app/src/main/java/io/legado/app/utils/HtmlFormatter.kt
@@ -23,7 +23,7 @@ object HtmlFormatter {
html ?: return ""
val keepImgHtml = html.replace(wrapHtmlRegex, "\n")
.replace(notImgHtmlRegex, "")
- .replace("[\\n\\s]+\$|^[\\n\\s]*".toRegex(), "")
+ .replace("[\\n\\s]+\$|^[\\n\\s]+".toRegex(), "")
.replace("\\s*\\n+\\s*".toRegex(), "\n")
val sb = StringBuffer()
@@ -36,7 +36,7 @@ object HtmlFormatter {
val urlBefore = url.substringBefore(',')
val strBefore = keepImgHtml.substring(appendPos, matcher.start())
sb.append(
- if(strBefore.isBlank()) '\n' else strBefore.replace("\n", "\n ") //缩进图片之间的非空白段落
+ if(strBefore.isBlank()) strBefore else strBefore.replace("\n", "\n ") //缩进图片之间的非空白段落
)
sb.append(
"
Date: Sun, 18 Jul 2021 14:21:57 +0800
Subject: [PATCH 6/6] Update BookContent.kt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化
---
.../main/java/io/legado/app/model/webBook/BookContent.kt | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt
index 364fa06df..1d71effc6 100644
--- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt
+++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt
@@ -52,7 +52,7 @@ object BookContent {
var contentData = analyzeContent(
book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl
)
- content.append(contentData.content).append("\n")
+ content.append(contentData.content)
if (contentData.nextUrl.size == 1) {
var nextUrl = contentData.nextUrl[0]
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
@@ -74,7 +74,7 @@ object BookContent {
)
nextUrl =
if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else ""
- content.append(contentData.content).append("\n")
+ content.append("\n").append(contentData.content)
}
}
Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}")
@@ -98,11 +98,10 @@ object BookContent {
}
asyncArray.forEach { coroutine ->
scope.ensureActive()
- content.append(coroutine.await()).append("\n")
+ content.append("\n").append(coroutine.await())
}
}
}
- content.deleteCharAt(content.length - 1)
var contentStr = content.toString()
val replaceRegex = contentRule.replaceRegex
if (!replaceRegex.isNullOrEmpty()) {