Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > Kindle Formats

Notices

Reply
 
Thread Tools Search this Thread
Old 08-08-2016, 07:37 AM   #1
arthurattwell
Member
arthurattwell is on a distinguished road
 
Posts: 12
Karma: 56
Join Date: Dec 2008
Device: None
Kindle Previewer: error converting from epub with specific CSS and `display: none`

I believe I have found a bug in Kindle Previewer 3.4 on Windows 10. Here are the details. I'd love to know if others have found anything similar or can shed more light on what causes it, or if I'm just wrong about something.

Essentially, conversion from epub throws an error when, in its CSS, `display: none` is set for a class that is referenced on its own *and* as a child of another element.

So this HTML:

Code:
<body>
<div>
<h1>Test heading</h1>
<p class="test-class">Test chapter text, with a class of 'test-class'. I'm going to try to hide this with CSS.</p>
</div>
</body>
And this CSS:

Code:
body .test-class, .test-class { display: none; }
will throw this conversion error:

Code:
Error(prcgen):E21018: Enhanced Mobi building failure, while parsing content in the file.
The error occurs during the phase indicated by KP3.4 as 'Optimizing'. KindleGen does not throw any error and converts fine. So the problem is probably not with the KindleGen component of Previewer.

The error message references the HTML file, even though (after extensive testing) it's clear the problem is with the CSS.

If anyone would like to try reproduce this, I've included the full HTML and CSS files for testing below. I used Sigil 0.9.6 to create the epub.

Naturally the workaround is simple: just structure your CSS differently. I happen to use Sass to generate my CSS, and if I nest classes to keep things neat in Sass, it's very easy to end up with this error-causing CSS structure.

HTML file in full:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../Styles/styles.css"/>
</head>
<body>
<div>
<h1>Test heading</h1>
<p class="test-class">Test chapter text, with a class of 'test-class'. I'm going to try to hide this with CSS.</p>
</div>
</body>
</html>
CSS file in full, with explanatory comments:

Code:
/* This CSS shows a bug in conversion with Kindle Previewer 3.4 on Windows 10
 * If a class is hidden with `display: none` and it is referenced both 
 * on its own and as a child of a parent element, conversion breaks:
 *
 * "Error(prcgen):E21018: Enhanced Mobi building failure, while parsing content in the file. Content: <Test heading> in file: C:\Users\Arthur\AppData\Local\Temp\mbp_7E0_8_8_B_15_10_F0_17D0_F50_1\OEBPS\Text\test-file.xhtml line: 7"
 *
 * The error occurs during the phase indicated by KP3.4 as 'Optimizing'
 * KindleGen (command line) does not throw any errors and converts fine.
 * 
 * So the following following line will cause the error:
 */


body .test-class, .test-class { display: none; }


/* This will also fail:

body .test-class { display: none; }
.test-class { display: none; }

*/

/* With this layout, the conversion does not seem to complete or error, but hangs:

body .test-class { display: none; }
div .test-class { display: none; }

*/
arthurattwell is offline   Reply With Quote
Old 08-09-2016, 09:28 AM   #2
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 6,598
Karma: 84812983
Join Date: Nov 2011
Location: Tampa Bay, Florida
Device: Kindles
Quote:
Originally Posted by arthurattwell View Post
I believe I have found a bug in Kindle Previewer 3.4 on Windows 10. Here are the details. I'd love to know if others have found anything similar or can shed more light on what causes it, or if I'm just wrong about something.
I tried your sample code and experienced the same failures with Previewer 3.4 beta. I agree that they are caused by bugs in the Previewer.

The Previewer has many other bugs that cause failure to convert books for Enhanced Typesetting. Since they happen silently, just reporting "Enhanced Typesetting not supported" for those books, it isn't obvious to the user just how buggy it really is.

Bugs that prevent generation of a MOBI file, such as you found, are rarer.
jhowell is offline   Reply With Quote
Advert
Old 08-10-2016, 07:14 AM   #3
Notjohn
mostly an observer
Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.Notjohn ought to be getting tired of karma fortunes by now.
 
Posts: 1,515
Karma: 987654
Join Date: Dec 2012
Device: Kindle
Quote:
Originally Posted by jhowell View Post
The Previewer has many other bugs that cause failure to convert books for Enhanced Typesetting. Since they happen silently, just reporting "Enhanced Typesetting not supported" for those books, it isn't obvious to the user just how buggy it really is.
Do you think the Kindle conversion (between Step 6 and Step 7 in the publishing process) is identical to the conversion done by KindleGen and Kindle Previewer? I build an epub and upload to the KDP, and I've never had a problem. A few of my older books however are not Enhanced Typesetting enabled. Do you think that means they are bug-infested?

Thanks for your work on KFX.
Notjohn is offline   Reply With Quote
Old 08-10-2016, 08:42 AM   #4
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 6,598
Karma: 84812983
Join Date: Nov 2011
Location: Tampa Bay, Florida
Device: Kindles
Quote:
Originally Posted by Notjohn View Post
Do you think the Kindle conversion (between Step 6 and Step 7 in the publishing process) is identical to the conversion done by KindleGen and Kindle Previewer? I build an epub and upload to the KDP, and I've never had a problem.
It appears to me that the KFX conversion process that occurs as part of Amazon book publishing is much more reliable than the version of that function in the Previewer. I suspect that it wasn't practical for them to include some parts of the production conversion process in the stand-alone Previewer so they had to re-implement some of the software. The new code has bugs.

Also, the stand-alone version appears to be more strict about what combinations of tags and styles it will allow when compared with the production version. I don't know why.

I am in the process of testing Previewer version 3.4 and it does appear to be better at conversion than the previous 3.x versions. It also produces more useful error messages when a conversion failure occurs. Unfortunately it doesn't display these messages to the user!

I am in the process of updating my KFX Output calibre plugin to support Previewer version 3.4. That plugin has the ability to capture conversion error messages from the Previewer and display them to the user. Even when they are cryptic, something is better than nothing.

Quote:
Originally Posted by Notjohn View Post
A few of my older books however are not Enhanced Typesetting enabled. Do you think that means they are bug-infested?
Older books that haven't yet been converted to support Enhanced Typesetting most likely have something in them that is being rejected by the conversion process. Feeding such a book though the Previewer may be useful in determining where the specific problem lies. You can iteratively cut out parts of the html/css until you narrow down what it doesn't like.
jhowell is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting epub to mobi through Kindle Previewer AThirstyMind Kindle Formats 26 12-28-2012 06:32 PM
Converting Epub to Mobi: Calibre v KindleGen/Kindle Previewer Jane12 Kindle Formats 16 11-22-2012 07:47 PM
Editing epub's style.css when converting to epub Pros Calibre 0 02-02-2012 01:13 PM
Kindle Previewer Displays HTML lists incorrectly when converting from EPUB Gandharva Kindle Developer's Corner 1 09-01-2011 06:52 PM
Trouble converting CBZ/CBR to epub for specific hardware (Literati) curtw Conversion 2 02-02-2011 09:12 PM


All times are GMT -4. The time now is 10:53 AM.


MobileRead.com is a privately owned, operated and funded community.