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.48k stars 231 forks source link

Write EPUB2 #225

Open BlackRobotMX opened 3 years ago

BlackRobotMX commented 3 years ago

I can create EPUB3 files from HTML, is there a way for the output to be EPUB2?

aerkalov commented 3 years ago

You can try epub.write_epub('test.epub', book, {"epub3_pages": False, "epub3_landmark": False, "epub2_guide": True}).

I am just looking at the code which was doing that (and million other things) and I think that might be it.

BlackRobotMX commented 3 years ago

I did try writing the epub with those options, bit still when I validate the epub i get that the version is 3.0.1.

Captura de Pantalla 2021-02-16 a la(s) 10 29 49

aerkalov commented 3 years ago

I checked the source code of epubcheck to see how it gets version of the EPUB because I forgot. So yes, this is hard coded into the code. Line 1086 in epub.py. But you also need to use those options.

        package_attributes = {'xmlns': NAMESPACES['OPF'],
                              'unique-identifier': self.book.IDENTIFIER_ID,
                              'version': '3.0'}

When file is created epubcheck will complain because of the different format for the metadata in the content.opf file. Plus will complain about html formatting, because template for creating pages is created for 3.0. Will take a look at it.

BlackRobotMX commented 3 years ago

Yes, I tried changing the version depending on the epub2_guide value, but as you say i get a lot of errors while validating the EPUB.

Captura de Pantalla 2021-02-17 a la(s) 9 36 47 Captura de Pantalla 2021-02-17 a la(s) 9 37 05 Captura de Pantalla 2021-02-17 a la(s) 9 37 25 Captura de Pantalla 2021-02-17 a la(s) 9 37 38