mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
修复web重复标题
This commit is contained in:
parent
2876c6f3e5
commit
b30ae2ef9e
@ -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,23 +64,23 @@ class ContentProcessor private constructor(
|
||||
reSegment: Boolean = true
|
||||
): List<String> {
|
||||
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 ->
|
||||
|
Loading…
Reference in New Issue
Block a user