mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
e2d187f38a
commit
493524b402
@ -119,14 +119,10 @@ class EpubFile(var book: Book) {
|
||||
|
||||
private fun getContent(chapter: BookChapter): String? {
|
||||
/*获取当前章节文本*/
|
||||
return getChildChapter(chapter, chapter.url)
|
||||
}
|
||||
|
||||
private fun getChildChapter(chapter: BookChapter, href: String): String? {
|
||||
epubBook?.let {
|
||||
val body = Jsoup.parse(String(it.resources.getByHref(href).data, mCharset)).body()
|
||||
val body =
|
||||
Jsoup.parse(String(it.resources.getByHref(chapter.url).data, mCharset)).body()
|
||||
|
||||
if (chapter.url == href) {
|
||||
val startFragmentId = chapter.startFragmentId
|
||||
val endFragmentId = chapter.endFragmentId
|
||||
/*一些书籍依靠href索引的resource会包含多个章节,需要依靠fragmentId来截取到当前章节的内容*/
|
||||
@ -135,7 +131,6 @@ class EpubFile(var book: Book) {
|
||||
body.getElementById(startFragmentId)?.previousElementSiblings()?.remove()
|
||||
if (!endFragmentId.isNullOrBlank() && endFragmentId != startFragmentId)
|
||||
body.getElementById(endFragmentId)?.nextElementSiblings()?.remove()
|
||||
}
|
||||
|
||||
/*选择去除正文中的H标签,部分书籍标题与阅读标题重复待优化*/
|
||||
var tag = Book.hTag
|
||||
|
@ -10,15 +10,14 @@ import java.util.Set;
|
||||
/**
|
||||
* The table of contents of the book.
|
||||
* The TableOfContents is a tree structure at the root it is a list of TOCReferences, each if which may have as children another list of TOCReferences.
|
||||
*
|
||||
* <p>
|
||||
* The table of contents is used by epub as a quick index to chapters and sections within chapters.
|
||||
* It may contain duplicate entries, may decide to point not to certain chapters, etc.
|
||||
*
|
||||
* <p>
|
||||
* See the spine for the complete list of sections in the order in which they should be read.
|
||||
*
|
||||
* @see Spine
|
||||
*
|
||||
* @author paul
|
||||
* @see Spine
|
||||
*/
|
||||
public class TableOfContents implements Serializable {
|
||||
|
||||
@ -46,6 +45,7 @@ public class TableOfContents implements Serializable {
|
||||
|
||||
/**
|
||||
* Calls addTOCReferenceAtLocation after splitting the path using the DEFAULT_PATH_SEPARATOR.
|
||||
*
|
||||
* @return the new TOCReference
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@ -86,7 +86,7 @@ public class TableOfContents implements Serializable {
|
||||
|
||||
/**
|
||||
* Adds the given Resources to the TableOfContents at the location specified by the pathElements.
|
||||
*
|
||||
* <p>
|
||||
* Example:
|
||||
* Calling this method with a Resource and new String[] {"chapter1", "paragraph1"} will result in the following:
|
||||
* <ul>
|
||||
@ -120,7 +120,7 @@ public class TableOfContents implements Serializable {
|
||||
|
||||
/**
|
||||
* Adds the given Resources to the TableOfContents at the location specified by the pathElements.
|
||||
*
|
||||
* <p>
|
||||
* Example:
|
||||
* Calling this method with a Resource and new int[] {0, 0} will result in the following:
|
||||
* <ul>
|
||||
@ -209,8 +209,11 @@ public class TableOfContents implements Serializable {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void getAllUniqueResources(Set<String> uniqueHrefs,
|
||||
List<Resource> result, List<TOCReference> tocReferences) {
|
||||
private static void getAllUniqueResources(
|
||||
Set<String> uniqueHrefs,
|
||||
List<Resource> result,
|
||||
List<TOCReference> tocReferences
|
||||
) {
|
||||
for (TOCReference tocReference : tocReferences) {
|
||||
Resource resource = tocReference.getResource();
|
||||
if (resource != null && !uniqueHrefs.contains(resource.getHref())) {
|
||||
@ -240,6 +243,7 @@ public class TableOfContents implements Serializable {
|
||||
|
||||
/**
|
||||
* The maximum depth of the reference tree
|
||||
*
|
||||
* @return The maximum depth of the reference tree
|
||||
*/
|
||||
public int calculateDepth() {
|
||||
|
Loading…
Reference in New Issue
Block a user