From 99fcd6956bcca177ab4af04e75fe78c7ee61a100 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Thu, 7 Dec 2023 11:51:39 +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 --- .../io/legado/app/model/localBook/EpubFile.kt | 21 ++++++++++--------- .../me/ag2s/epublib/epub/NCXDocumentV3.java | 20 +++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) 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 f71ee340e..449893ac9 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 @@ -134,16 +134,6 @@ class EpubFile(var book: Book) { } private fun getContent(chapter: BookChapter): String? { - /** - * - * ...titlepage.xhtml - * 大多数epub文件的封面页都会带有cover,可以一定程度上解决封面读取问题 - */ - if (chapter.url.contains("titlepage.xhtml") || - chapter.url.contains("cover") - ) { - return "" - } /*获取当前章节文本*/ val contents = epubBookContents ?: return null val nextChapterFirstResourceHref = chapter.getVariable("nextUrl").substringBeforeLast("#") @@ -201,6 +191,17 @@ class EpubFile(var book: Book) { } private fun getBody(res: Resource, startFragmentId: String?, endFragmentId: String?): Element { + /** + * + * ...titlepage.xhtml + * 大多数epub文件的封面页都会带有cover,可以一定程度上解决封面读取问题 + */ + if (res.href.contains("titlepage.xhtml") || + res.href.contains("cover") + ) { + return Jsoup.parseBodyFragment("") + } + // Jsoup可能会修复不规范的xhtml文件 解析处理后再获取 var bodyElement = Jsoup.parse(String(res.data, mCharset)).body() bodyElement.children().run { diff --git a/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java b/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java index 3cce0dd6e..1b508c5f4 100644 --- a/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java @@ -136,18 +136,18 @@ public class NCXDocumentV3 { } private static List doToc(Node n, EpubBook book) { - List result = new ArrayList<>(); - if (n == null || n.getNodeType() != Document.ELEMENT_NODE) { - return result; - } else { - Element el = (Element) n; - NodeList nodeList = el.getElementsByTagName(XHTMLTgs.li); - for (int i = 0; i < nodeList.getLength(); i++) { - result.add(readTOCReference((Element) nodeList.item(i), book)); - } + return new ArrayList<>(); } - return result; + + Element el = (Element) n; + Node node = el.getElementsByTagName(XHTMLTgs.ol).item(0); + + if (node == null || node.getNodeType() != Document.ELEMENT_NODE) { + return new ArrayList<>(); + } + + return readTOCReferences(node.getChildNodes(), book); }