修复web重复标题

pull/1395/head
gedoor 3 years ago
parent 2876c6f3e5
commit b30ae2ef9e
  1. 5
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 2
      app/src/main/java/io/legado/app/help/ContentHelp.kt
  3. 8
      app/src/main/java/io/legado/app/help/ContentProcessor.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)

@ -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(), ":“")

@ -64,7 +64,6 @@ class ContentProcessor private constructor(
reSegment: Boolean = true
): List<String> {
var mContent = content
if (includeTitle) {
//去除重复标题
try {
val name = Pattern.quote(book.name)
@ -74,13 +73,14 @@ class ContentProcessor private constructor(
} catch (e: Exception) {
AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
}
//重新添加标题
mContent = chapter.getDisplayTitle() + "\n" + mContent
}
if (reSegment && book.getReSegment()) {
//重新分段
mContent = ContentHelp.reSegment(mContent, chapter.title)
}
if (includeTitle) {
//重新添加标题
mContent = chapter.getDisplayTitle() + "\n" + mContent
}
if (useReplace && book.getUseReplaceRule()) {
//替换
getReplaceRules().forEach { item ->

Loading…
Cancel
Save