-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: misplaced subsection position in toc.ncx #13
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ChengShusss.
thanks for your pull request.
as i see some of test not pass can you check that?
it can be helpful if you add a screenshot from before and after of table of content too.
As we can see in file change tab, this pull request only change one line. |
can you send an screenshot of table of content before after too? |
Sorry to misunderstand the meaning of table of content, here is the difference before and after: demo code: package main
import (
"fmt"
"log"
epub "github.com/go-shiori/go-epub"
)
func main() {
// Create a new EPUB
e, err := epub.NewEpub("My title")
if err != nil {
log.Println(err)
}
// Add a section
sectionBody := `<h1>Section 1</h1>
<p>This is a paragraph.</p>`
parent1, err := e.AddSection(sectionBody, "Section 1", "", "")
if err != nil {
log.Println(err)
}
// Add a subsection
subsectionBody := `<h2>Section 1-1</h2>
<p>This is a paragraph of h2.</p>`
_, err = e.AddSubSection(parent1, subsectionBody, "Section 1-1", "SubSectionName", "")
if err != nil {
log.Println(err)
}
// Write the EPUB
err = e.Write("My EPUB.epub")
if err != nil {
// handle error
fmt.Printf("Falied to create epub, err: %v\n", err)
}
} toc.ncx before modify:
And this is after:
|
Now i can see better your change. but visually and functionality on my eBook reader are the same as each other
do you test that in specific device and any specific program not show them same as each other? |
It is tested with sumatraPDF to check table of content, and on sumatraPDF, it acts expectantly. Maybe it is because epub has several ways to gain toc and sumatra PDF just take toc.ncx, while other readers do not use this method? Please give me some time to find out why. |
After search, we could get these messages:
Some experiment:
Then we can summarize: Only reader parse epub as EPUB2 (use toc.ncx), the difference would show up. That's all and thanks for you valuable question! ref: |
In sumatraPDF or readers limit to EPUB 2 |
@Monirzadeh @ChengShusss I see tests passing at the moment, is there anything specific for me to check here? |
@fmartingr at the moment we get this |
Let me run the test locally to check, but the CI is passing at the moment. |
Tests ran correctly on my mac, and I re-run all tests here in Github and passed as well. I think it was a network error at the time. |
For toc.ncx in epub V2, a subsection navigate label should be placed under section label, while subsection is misplaced parallel to section.
This is because function toc.addSubSection (toc.go: 173) used opposite condition for ncxXML. When there is parent section for subsection, code goes into a situation assuming no parent section, which means taking this subsection as a lonely section.
So, simply exchange the condition would work.
And for code style consistency, use same style like navXML part (toc.go: 191).