aerkalov / ebooklib

Python E-book library for handling books in EPUB2/EPUB3 format -
https://ebooklib.readthedocs.io/
GNU Affero General Public License v3.0
1.46k stars 227 forks source link

Basic EPub3 output doesn't pass the official validator #130

Open foodpoison opened 7 years ago

foodpoison commented 7 years ago

Hi there,

I'm using the current stable release (0.16) so I'm not sure if this has changed since then, but at the moment it'll fail the validator, with at least a navPoint issue in the NCX, if I were to just use book.add_item(epub.EpubNcx()). Specifically the error is Error while parsing file 'element "navMap" incomplete; missing required element "navPoint"'.

Opening up the epub, I would get an ncx that contains an empty navMap element, specifically it would look like this: <navMap/>, whilst, a valid one might look like this:

  <navMap>
      <navPoint id="navpoint-1" playOrder="1">
         <navLabel>
            <text></text>
         </navLabel>
         <content src="cover.xhtml"/>
      </navPoint>
   </navMap>

The validator is here: EPUB Validator

CtrlAltDefeat94 commented 7 years ago

Getting similar errors using the same validator: image

Using version 0.16

aerkalov commented 7 years ago

@foodpoison you need to add EpubNav also. Check the samples/01_basic_create/create.py file. It validates just fine (I use command line epub validator but i validated over the web now also). Can you put your code here to see what is happening.

aerkalov commented 7 years ago

@CtrlAltDefeat94 Check my previous comment. Also, can you share your code to see what is happening.

CtrlAltDefeat94 commented 7 years ago

book = epub.read_epub(filepath) book.set_title(title) epub.write_epub(filepath, book, {})

What I'm trying to achieve is to alter an existing epub and change one or multiple tags(title, author, etc), but I guess it takes more than that.

aerkalov commented 7 years ago

@CtrlAltDefeat94 It is used more or less - you read existing epub, take what you want and create new epub. There is always some garbage you want to exclude from the original file and the library is not going to do it out of the box. You can check the sample here (end of the file) - https://github.com/sourcefabric/Booktype/blob/master/lib/booktype/apps/export/utils.py

But to be honest, there is no reason why your sample file shouldn't work (but I know it never worked out of the box). Will play more with it to see what is going on there.

CtrlAltDefeat94 commented 7 years ago

Did you get time to play with things? I have yet to get that sample to work.

aerkalov commented 7 years ago

@CtrlAltDefeat94 There is some progress at the moment. I am testing it with IDPF sample files, which are all valid. What kind of files have you used? Were they already valid or just random EPUB files. Also, if it is not a problem could you send me one of the input files you used so I could test them also.

CtrlAltDefeat94 commented 7 years ago

The file I'm testing with; https://www.dropbox.com/s/lomao303j5dp5b4/2.%20Blood%20Enemy.epub?dl=0 The EPUB files I'm using aren't all retail, but I wouldn't call them random files. Could you share your code so I can try that?

foodpoison commented 7 years ago

@aerkalov OK I think I found the difference between your sample code and mine. I don't have the book.toc = ... section. I removed that part from your working sample code and indeed the navMap disappears.

The problem is, I'm making a children's book, which is roughly 15 pages of just fixed layout pictures with very little words, just one story with no chapters to speak of, so I don't actually want to include a toc at the start of the book. Is there something else that I can do to fix this?

deborahgu commented 6 years ago

@foodpoison the toc and the navMap are effectively the same thing, just one from epub 2 and the other from epub 3. From the epub content documents 3.0 documentation:

The toc nav element corresponds to the navMap element in the superseded NCX

Just as the navMap was required in Epub 2, the toc is required in Epub 3. One of the IDPF sample epubs is for a trivial, one-page epub, and you can see its navMap and its toc.

In order to be a legal epub it needs at least a minimal toc, even if that minimal toc contains only one entry pointing to the main content. My suspicion is that this is why @aerkalov's code requires that you create one in order to get the other.

drops777 commented 1 year ago

@foodpoison For some reason InDesign generated an empty navMap attribute for me, too, with navPoint missing. EpubCheck reported this as an error, the same as yours. Amateur fix: Epub check also came back with Info about not being able to embed some fonts. I replaced these fonts in InDesign with more basic/generic ones. Then I checked what Paragraph Styles I used for the Table of Contents - again, replaced fonts with non-fancy fonts. Final action: I changed TOC Style from my style to [Default]. This seems to have fixed the error as another run through EpubCheck returned zero errors. Maybe this could help someone.

c1924959470 commented 1 year ago

   您好!您的来信我已接受,我会尽快回复您。