From b30ae2ef9e858f24d459e2e22cc5e86bbec625ae Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 12 Oct 2021 20:10:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dweb=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/api/controller/BookController.kt | 5 ++-- .../java/io/legado/app/help/ContentHelp.kt | 2 +- .../io/legado/app/help/ContentProcessor.kt | 24 +++++++++---------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index 78226e9c0..56831f09e 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -132,7 +132,7 @@ object BookController { val contentProcessor = ContentProcessor.get(book.name, book.origin) saveBookReadIndex(book, index) return returnData.setData( - contentProcessor.getContent(book, chapter, content) + contentProcessor.getContent(book, chapter, content, includeTitle = false) .joinToString("\n") ) } @@ -145,7 +145,8 @@ object BookController { val contentProcessor = ContentProcessor.get(book.name, book.origin) saveBookReadIndex(book, index) returnData.setData( - contentProcessor.getContent(book, chapter, content).joinToString("\n") + contentProcessor.getContent(book, chapter, content, includeTitle = false) + .joinToString("\n") ) } catch (e: Exception) { returnData.setErrorMsg(e.msg) diff --git a/app/src/main/java/io/legado/app/help/ContentHelp.kt b/app/src/main/java/io/legado/app/help/ContentHelp.kt index b31580cbd..ad742d058 100644 --- a/app/src/main/java/io/legado/app/help/ContentHelp.kt +++ b/app/src/main/java/io/legado/app/help/ContentHelp.kt @@ -59,7 +59,7 @@ object ContentHelp { buffer.append(findNewLines(s, dict)) } buffer = reduceLength(buffer) - content1 = ("$chapterName\n\n" + buffer.toString() // 处理章节头部空格和换行 + content1 = (buffer.toString() // 处理章节头部空格和换行 .replaceFirst("^\\s+".toRegex(), "") .replace("\\s*[\"”“]+[\\s]*[\"”“][\\s\"”“]*".toRegex(), "”\n“") .replace("[::][”“\"\\s]+".toRegex(), ":“") diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 19df6b6f7..7c1e319c4 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -64,23 +64,23 @@ class ContentProcessor private constructor( reSegment: Boolean = true ): List { var mContent = content - if (includeTitle) { - //去除重复标题 - try { - val name = Pattern.quote(book.name) - val title = Pattern.quote(chapter.title) - val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex() - mContent = mContent.replace(titleRegex, "") - } catch (e: Exception) { - AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) - } - //重新添加标题 - mContent = chapter.getDisplayTitle() + "\n" + mContent + //去除重复标题 + try { + val name = Pattern.quote(book.name) + val title = Pattern.quote(chapter.title) + val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s|\\p{P})+".toRegex() + mContent = mContent.replace(titleRegex, "") + } catch (e: Exception) { + AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) } if (reSegment && book.getReSegment()) { //重新分段 mContent = ContentHelp.reSegment(mContent, chapter.title) } + if (includeTitle) { + //重新添加标题 + mContent = chapter.getDisplayTitle() + "\n" + mContent + } if (useReplace && book.getUseReplaceRule()) { //替换 getReplaceRules().forEach { item ->