This commit is contained in:
Horis 2024-01-18 16:32:37 +08:00
parent 6979054a57
commit 88476f7a82
4 changed files with 28 additions and 9 deletions

View File

@ -45,9 +45,20 @@ class AnalyzeByJSoup(doc: Any) {
/**
* 合并内容列表,得到内容
*/
internal fun getString(ruleStr: String) =
if (ruleStr.isEmpty()) null
else getStringList(ruleStr).takeIf { it.isNotEmpty() }?.joinToString("\n")
internal fun getString(ruleStr: String): String? {
if (ruleStr.isEmpty()) {
return null
}
val list = getStringList(ruleStr)
if (list.isEmpty()) {
return null
}
if (list.size == 1){
return list.first()
}
return list.joinToString("\n")
}
/**
* 获取一个字符串

View File

@ -295,9 +295,12 @@ class AnalyzeRule(
}
}
if (result == null) result = ""
val str = if (unescape) {
StringEscapeUtils.unescapeHtml4(result.toString())
} else result.toString()
val resultStr = result.toString()
val str = if (unescape && resultStr.indexOf('&') > -1) {
StringEscapeUtils.unescapeHtml4(resultStr)
} else {
resultStr
}
if (isUrl) {
return if (str.isBlank()) {
baseUrl ?: ""

View File

@ -137,8 +137,11 @@ object LocalBook {
"获取本地书籍内容失败\n${e.localizedMessage}"
}
if (book.isEpub) {
content = content?.replace("<img", "< img", true) ?: return null
return StringEscapeUtils.unescapeHtml4(content)
content ?: return null
if (content.indexOf('&') > -1) {
content = content.replace("<img", "< img", true)
return StringEscapeUtils.unescapeHtml4(content)
}
}
return content
}

View File

@ -169,7 +169,9 @@ object BookContent {
//获取正文
var content = analyzeRule.getString(contentRule.content, unescape = false)
content = HtmlFormatter.formatKeepImg(content, rUrl)
content = StringEscapeUtils.unescapeHtml4(content)
if (content.indexOf('&') > -1) {
content = StringEscapeUtils.unescapeHtml4(content)
}
//获取下一页链接
if (getNextPageUrl) {
val nextUrlRule = contentRule.nextContentUrl