gutenbergtools / ebookmaker

The Project Gutenberg tool to generate EPUBs and other ebook formats.
GNU General Public License v3.0
84 stars 18 forks source link

Mobi file losing character with CSS `first-letter` #166

Closed windymilla closed 1 year ago

windymilla commented 1 year ago

Using ebookmaker 0.12.23 to convert the small attached HTML , the first letter of the sentence ("W") is missing from the Kindle mobi file created, but is visible in the other files.

The relevant section of CSS is

p.drop-cap:first-letter
{
  visibility: hidden;
}
p.drop-cap:first-letter
{
  visibility: visible;
}

If p.drop-cap:first-letter is changed to p.drop-cap (to select the whole paragraph), it works as expected. Alternatively, instead of setting visibility, if you set color: red for the first letter, then set it to blue, that works as expected. It appears to be the combination of first-letter and visibility that causes the problem.

The reason this is an issue, is that CSS based on this has been the recommended method to deal with illustrated dropcaps for many years: the first letter is hidden (replaced by the dropcap image), and in the epub2/mobi it is made visible again (and the image is hidden). Of course, there is more CSS involved, and the second selector has ".x-ebookmaker-2" before it, to just restore the letter for epub2/mobi. The version above is simplified as much as possible to avoid distractions - it is nothing to do with the .x-ebookmaker selector.

Using ebookmaker 0.11.30 (bundled in a previous release of Guiguts), the "W" is visible. I'm fairly sure the 11.30 version is using kindlegen to create the mobi, whereas 12.23 is using Calibre, so that is a possible/probable cause. This is probably why the issue has only just started to be reported.

eshellman commented 1 year ago

I would check if pseudo classes are officially supported in EPUB2.

I am no longer able to do development or testing with kindlegen due to Amazon's discontinuation of kindlegen, but I'd be happy to consider PR's from somone who is.

windymilla commented 1 year ago

The odd thing is that it is a pseudo class that hides the first letter, then the identical pseudo class that restores it. Only the first of those appears to have an effect. Also, it's only with the visibility attribute. The colour attribute works fine with a pseudo class.

eshellman commented 1 year ago

I've seen similar behavior for mobi in other contexts. My mental model is that it doesn't know how to hide things, it can only discard them. Thus unhiding is impossible.

windymilla commented 1 year ago

But only for the pseudo class first-letter. It appears to be able to hide a whole paragraph and then unhide it. But I agree - when I converted the mobi to an epub2 (in Calibre) so I could look inside, the first letter was missing completely.

eshellman commented 1 year ago

Should I keeo this issue open?

windymilla commented 1 year ago

Since you have no way of fixing it, there's probably not much point :)

eshellman commented 1 year ago

OK thanks!