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 ->