Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Dec 7, 2023
1 parent 071a348 commit 99fcd69
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 11 additions & 10 deletions app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,6 @@ class EpubFile(var book: Book) {
}

private fun getContent(chapter: BookChapter): String? {
/**
* <image width="1038" height="670" xlink:href="..."/>
* ...titlepage.xhtml
* 大多数epub文件的封面页都会带有cover,可以一定程度上解决封面读取问题
*/
if (chapter.url.contains("titlepage.xhtml") ||
chapter.url.contains("cover")
) {
return "<img src=\"cover.jpeg\" />"
}
/*获取当前章节文本*/
val contents = epubBookContents ?: return null
val nextChapterFirstResourceHref = chapter.getVariable("nextUrl").substringBeforeLast("#")
Expand Down Expand Up @@ -201,6 +191,17 @@ class EpubFile(var book: Book) {
}

private fun getBody(res: Resource, startFragmentId: String?, endFragmentId: String?): Element {
/**
* <image width="1038" height="670" xlink:href="..."/>
* ...titlepage.xhtml
* 大多数epub文件的封面页都会带有cover,可以一定程度上解决封面读取问题
*/
if (res.href.contains("titlepage.xhtml") ||
res.href.contains("cover")
) {
return Jsoup.parseBodyFragment("<img src=\"cover.jpeg\" />")
}

// Jsoup可能会修复不规范的xhtml文件 解析处理后再获取
var bodyElement = Jsoup.parse(String(res.data, mCharset)).body()
bodyElement.children().run {
Expand Down
20 changes: 10 additions & 10 deletions modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ public static Resource read(EpubBook book, EpubReader epubReader) {
}

private static List<TOCReference> doToc(Node n, EpubBook book) {
List<TOCReference> 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);
}


Expand Down

0 comments on commit 99fcd69

Please sign in to comment.