Incorrect nesting of sections in FB2 output

Bug #1393514 reported by David Booth on 2014-11-17
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Undecided
John Schember

Bug Description

I am developing an input plugin for Bibles in the OSIS format. The plugin creates a TOC with 3 levels - Testaments, Books and Chapters. This works fine for EPUB output. For FB2 output I am using "--sectionize toc" on the ebook-convert command line to try to create an equivalent table of contents. However, the actual table of contents I see when viewing the the FB2 output in either Calibre or FBReader has all TOC entries except for the first Testamant and Book at level 3. i.e.:

Old Testament
     Genesis
            Chapter 1
             ......
             Chapter 50
             Exodus (should be a level 2 entry, but is actually at level 3)
             Chapter 1
             ....

This appears to be the result of incorrect nesting of sections in the FB2 output. At the end of a book there should be two </section> tags (to terminate chapter and book) and at the end of a testament there should be three </section> tags, but in each case there is only one such tag, other than at the very end of the document body.

I am using Calibre 2.10 on Windows 7.

David Booth (david-booth12) wrote :

Changing the component for this bug.

 assignee user-none
 tag fb2-output
 status triaged

Changed in calibre:
assignee: nobody → John Schember (user-none)
status: New → Triaged
John Schember (user-none) wrote :

I'll take a look at this this weekend.

Changed in calibre:
status: Triaged → In Progress
John Schember (user-none) wrote :

The sectionize based on toc is a a best guess effort. It takes a number various options that can impact the behavaior such as, "adjust the "Structure Detection" and/or "Table of Contents" settings (turn on "Force use of auto-generated Table of Contents"). It was never meant to be a perfect conversion of toc to section.

FB2 being such a unique format and this feature being best used with sectionize based on file (the reason this was created in the first place), I'm not willing to work on this issue. If you'd like to look into it further and attach a patch I'm willing to review it but otherwise I'm closing this as won't fix.

Changed in calibre:
status: In Progress → Won't Fix

I have had a look at the code and have found there is a simple one-line fix. I have set up a Calibre development environment and have tested the fix. The updated file is attached. The line I have changed is line 438, within the function dump_text(). The original line was:                    if not (newlevel > self.section_level):
The changed line is:                    while not (newlevel > self.section_level):

The original code handled the case 'newlevel==self.section_level' correctly, but not the case 'newlevel<self.section_level', which requires more than one '</section>' to be inserted.
RegardsDavid Booth
      From: John Schember <email address hidden>
 To: <email address hidden>
 Sent: Saturday, 29 November 2014, 13:21
 Subject: [Bug 1393514] Re: Incorrect nesting of sections in FB2 output

The sectionize based on toc is a a best guess effort. It takes a number
various options that can impact the behavaior such as, "adjust the
"Structure Detection" and/or "Table of Contents" settings (turn on
"Force use of auto-generated Table of Contents"). It was never meant to
be a perfect conversion of toc to section.

FB2 being such a unique format and this feature being best used with
sectionize based on file (the reason this was created in the first
place), I'm not willing to work on this issue. If you'd like to look
into it further and attach a patch I'm willing to review it but
otherwise I'm closing this as won't fix.

** Changed in: calibre
      Status: In Progress => Won't Fix

--
You received this bug notification because you are subscribed to the bug
report.
https://bugs.launchpad.net/bugs/1393514

Title:
  Incorrect nesting of sections in FB2 output

Status in calibre: e-book management:
  Won't Fix

Bug description:
  I am developing an input plugin for Bibles in the OSIS format. The
  plugin creates a TOC with 3 levels - Testaments, Books and Chapters.
  This works fine for EPUB output. For FB2 output I am using "--
  sectionize toc" on the ebook-convert command line to try to create an
  equivalent table of contents. However, the actual table of contents I
  see when viewing the the FB2 output in either Calibre or  FBReader has
  all TOC entries except for the first Testamant and Book at level 3.
  i.e.:

  Old Testament
      Genesis
              Chapter 1
              ......
              Chapter  50
              Exodus                              (should be a level 2 entry, but is actually at level 3)
              Chapter 1
              ....

  This appears to be the result of incorrect nesting of sections in the
  FB2 output. At the end of a book there should be two </section> tags
  (to terminate chapter and book) and at the end of a testament there
  should be three </section> tags, but in each case there is only one
  such tag, other than at the very end of the document body.

  I am using Calibre 2.10 on Windows 7.

To manage notifications about this bug go to:
https://bugs.launchpad.net/calibre/+bug/1393514/+subscriptions

John Schember (user-none) wrote :

The change looks sane. Only Kovid has commit rights. You can create a branch for him to pull from on github to commit the change or ask him to make it for you since it's a single line.

Changed in calibre:
status: Won't Fix → Confirmed

Fixed in branch master. The fix will be in the next release. calibre is usually released every Friday.

 status fixreleased

Changed in calibre:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers