Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort definitions in SCSS files to make them pass validators #485

Merged

Conversation

LPT-BlubbY
Copy link
Contributor

I came across asciidoctor-epub3 some time ago and use it for my own projects. Back then I already noticed that the CSS files placed into the resulting *.epub file were causing many warnings and errors in validators.

So, after using it for some years now, I finally got the time to fix all the issues. I verified my changes with the hardware I have at hand here (read: Calibre 7.6.0 and my dusty Kobo GloHD with firmware version 3.19.5761 from December 2015). Both readers don't show any differences in the tests I did, but I can't cover all devices out there, of course.

There have been no changes in the semantics, just changes in the order of the individual CSS definitions.

I would kindly ask to review my changes and get them integrated at some point, but I also noticed that the files follow a more visual approach in the order they define the individual styles: from top to bottom. Header and chapter definitions come first in the files, then the stuff which goes into the content area (tables, paragraphs, images, ...) and finally there are definitions for footers. So I would also understand if my changes are not considered an improvement and keeping the current order being favored.

Fixed font namings, as their names mentioned in the CSS were not matching the
fonts' internal name in the *.ttf file. I'm sure this isn't important for
eBook readers, but it doesn't hurt either to have it matching now.

Added generic font-family to all symbol-only fonts to please CSS validators.
That generic font will never be used and, as eBook readers would have to go
with some font anyways (in case e.g. the "Font Awesome" is missing in the
output document), I decided to use "monospace" here.

Fixed missing leading 0s in decimal numbers.

Commented-out duplicate margin and font-size definitions in <h4> block. I
assume eBook readers parse the document from top to bottom and take the last
definition they find, so I disabled the definition at the top and kept the
one at the bottom alive.

Tested and verified with Calibre and my ancient Kobo GloHD device.
No semantical changes, just changed the sequence of some blocks due to
CSS validators complaining about it.

Moved <th.halign> and <th.valign> further down

Moved <blockquote> and <pre> blocks further up before <div.abstract>

Moved <div.footnotes> before <table.table td>

Merged the two <dt> blocks into a single one.

Tested and verified my changes with Calibre and my ancient Kobo GloHD device.
Only 20 errors remaining with this change (and my previous commit).
Further changes in sequence:

Moved <dl dd> down just after <dd>

Moved ul, ul ul, ..., ol, ol ol, ... further up to the other <ul> definition

Moved <figure.image> further up before <.chapter-header p.byline img>

Moved <div.verse > pre> before <figure.listing > figcaption + pre>

Had to split <th> and <td> from their existing block to move them
before <table.table th> and <table.table td>

Tested and verified my changes with Calibre and my ancient Kobo GloHD device.
Only 12 errors remaining now.
Final commit changing the sequence of blocks to please CSS validators

Moved <table.table-grid-all th> and <table.table-grid-all td> up a bit to
define it before <table.table thead th>

Moved <hr.pagebreak + *> further up before <table.table thead th>

Moved <table.table-grid-all thead tr > *:last-child> further down
after <table.table-grid-cols tbody tr > td:last-child>

Moved <table.table-grid-cols th> and <table.table-grid-cols td> a bit up
before <table.table thead th>

Validator now says: "0 errors", yay!

Tested and verified my changes yet again with Calibre and my ancient
Kobo GloHD device.
@slonopotamus
Copy link
Contributor

Hi, my main question here is: what validator you use (and how) and whether we can integrate it into asciidoctor-epub3 testsuite to make sure CSS stays valid in the future. We already use EPUBCheck, but it doesn't report any issues in current CSS.

@LPT-BlubbY
Copy link
Contributor Author

Hi, thanks for the info and quick response.

I used the validator integrated into Calibre (its "eBook Editor"). From the menu it can run checks on the whole book and came up with a total of 70+ issues. It's interesting that EPUBCheck didn't report anything, although I have to admit that I didn't use that tool in the past.

Nevertheless, I just gave it a try, installed it and fired it against a book. My workflow for this test was this:

  1. Extract the *.epub file on disk (having it built with the old asciidoctor CSS files, of course)
  2. Edit the styles/epub3.css file
  3. Compress everything to a ZIP archive again and renamed it to *.epub
  4. Start EPUBCheck with parameter -w which should bring up warnings, errors and fatals

My first impressions are that this tool does many checks regarding the overall structure and the metadata inside, including the package OPF. So it straight pointed out that in my test workflow here I accidentally compressed the mimetype file as well which is a no-no for EPUB... So that was all reported well. However, for some reason it looks like it doesn't do a full compliance check on the CSS files.

I tried the following:

  • I changed an arbitrary margin definitions in that epub3.css file from 10 pixels to a non-existing unit. In my case I called it "glue", so this particular part now read: margin-top: 100glue;. That unit doesn't exist in CSS, yet EPUBCheck didn't say anything about it, not even a warning.
  • Next I tried to add a non-existing attribute into the CSS: Instead of margin-top, I wrote LeckoMio: 100glue;. Again, no word from EPUBCheck (although AFAIK there is no CSS keyword which starts with an uppercase letter)
  • Finally, I broke CSS by adding the same keyword without a unit and without the colon, so it just read: LeckoMio;. Interestingly, this time EPUBCheck responded with a fail.

Worth noting that all 3 cases were detected fine by Calibre's eBook Editor and produced red error messages there.

Maybe you can give that a try on your end as well to see if you can reproduce my results? I used EPUBCheck version 4.2.6, but maybe I missed some parameters.

My command line is: epubcheck -w /path/to/the/file.epub

@slonopotamus
Copy link
Contributor

I used the validator integrated into Calibre (its "eBook Editor"). From the menu it can run checks on the whole book and came up with a total of 70+ issues.

Ah, that's the bit I was missing, thanks.

WRT EPUBCheck: asciidoctor-epub3 has builtin support for that. You install epubcheck-ruby gem, make sure java is available on PATH and simply pass -a ebook-validate argument to asciidoctor-epub3. It is true that EPUBCheck does not have a strong CSS validation.

@LPT-BlubbY
Copy link
Contributor Author

Talking about automation for testing:
I just did a search on this matter, but it looks like the Calibre editor has no option to perform these checks from command line. Also, I guess, it would require some UI in order to start. So that's not an option. However, maybe the foundation of the Calibre applications is something which could be integrated into asciidoctor-epub3 as well (like some sort of CSS LINT library).

@slonopotamus slonopotamus merged commit 88c0172 into asciidoctor:main Nov 19, 2024
9 checks passed
@slonopotamus slonopotamus added this to the next milestone Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants