From ac9915ec36f417027afdc02eda10c1b69ff08622 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Fri, 6 Jan 2023 14:14:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/lib/webdav/WebDav.kt | 3 ++- .../io/legado/app/model/analyzeRule/AnalyzeByXPath.kt | 5 +++++ .../java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 6 ++++++ .../main/java/io/legado/app/model/localBook/EpubFile.kt | 8 +++++++- .../java/io/legado/app/ui/book/cache/CacheViewModel.kt | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 838f3713b..baf435de4 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -17,6 +17,7 @@ import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import org.intellij.lang.annotations.Language import org.jsoup.Jsoup +import org.jsoup.parser.Parser import java.io.File import java.io.FileOutputStream import java.io.InputStream @@ -150,7 +151,7 @@ open class WebDav(val path: String, val authorization: Authorization) { */ private fun parseBody(s: String): List { val list = ArrayList() - val document = Jsoup.parse(s) + val document = Jsoup.parse(s, Parser.xmlParser()) val ns = document.findNSPrefix("DAV:") val elements = document.findNS("response", ns) val urlStr = httpUrl ?: return list diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt index 3e5a50698..5b9937324 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt @@ -2,8 +2,10 @@ package io.legado.app.model.analyzeRule import android.text.TextUtils import androidx.annotation.Keep +import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import org.jsoup.parser.Parser import org.jsoup.select.Elements import org.seimicrawler.xpath.JXDocument import org.seimicrawler.xpath.JXNode @@ -30,6 +32,9 @@ class AnalyzeByXPath(doc: Any) { if (html1.endsWith("") || html1.endsWith("")) { html1 = "${html1}
" } + if (html1.trim().startsWith(" get(urlNoQuery, fieldMap, true) } + }.let { + val isXml = it.raw.body?.contentType()?.toString() + ?.matches("(application|text)/\\w*\\+?xml.*".toRegex()) == true + if (isXml && it.body?.trim()?.startsWith("" + it.body) + } else it } } return strResponse diff --git a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt index 3b233a22a..b1a27240b 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt @@ -13,11 +13,11 @@ import me.ag2s.epublib.domain.EpubBook import me.ag2s.epublib.domain.Resource import me.ag2s.epublib.domain.TOCReference import me.ag2s.epublib.epub.EpubReader +import me.ag2s.epublib.util.StringUtil import me.ag2s.epublib.util.zip.AndroidZipFile import org.jsoup.Jsoup import org.jsoup.nodes.Element import org.jsoup.select.Elements -import splitties.init.appCtx import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -173,6 +173,12 @@ class EpubFile(var book: Book) { } //title标签中的内容不需要显示在正文中,去除 elements.select("title").remove() + elements.select("img").forEach { + val src = it.attr("src") + val path = chapter.url.substringBeforeLast("/") + "/" + val absSrc = StringUtil.collapsePathDots(path + src) + it.attr("src", absSrc) + } var html = elements.outerHtml() val tag = Book.rubyTag if (book.getDelTag(tag)) { diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index e30a5f2e7..ff77b7045 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -227,7 +227,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { .getContent( book, chapter, - content ?: "null", + content ?: if (chapter.isVolume) "" else "null", includeTitle = !AppConfig.exportNoChapterName, useReplace = useReplace, chineseConvert = false,