w3c / epubcheck

The conformance checker for EPUB publications
https://www.w3.org/publishing/epubcheck/
BSD 3-Clause "New" or "Revised" License
1.64k stars 402 forks source link

Errors for nested <div> in epub 3 #1287

Closed tthkbw closed 2 years ago

tthkbw commented 2 years ago

I have created an epub 3 file that contains nested <div> elements. epubcheck throws errors for all of these:

ERROR(RSC-005): ./paged_epubs/xxx.epub/OEBPS/c01_r1.xhtml(32,231): Error while
 parsing file: element "div" not allowed here; expected the element end-tag, text, element "a", "abbr", "area
", "audio", "b", "bdi", "bdo", "br", "button", "canvas", "cite", "code", "data", "datalist", "del", "dfn", "e
m", "embed", "epub:switch", "i", "iframe", "img", "input", "ins", "kbd", "label", "link", "map", "mark", "met
a", "meter", "ns1:math", "ns2:svg", "object", "output", "picture", "progress", "q", "ruby", "s", "samp", "scr
ipt", "select", "small", "span", "strong", "sub", "sup", "template", "textarea", "time", "u", "var", "video" 
or "wbr" (with xmlns:ns1="http://www.w3.org/1998/Math/MathML" xmlns:ns2="http://www.w3.org/2000/svg") or an e
lement from another namespace

These errors do not affect the display of the added nested <div> element in ebook readers I have tested (limited to Calibre and Apple Books at this point).

Nested <div> is allowed in html, and I don't find anything about not allowing them in epub 3.

What am I missing?

rdeltour commented 2 years ago

Thanks for the report 😊 Are you able to send us a file sample to help us reproduce the issue? Also, have you checked with the HTML validator? (it may provide more context).

mattgarrish commented 2 years ago

Just going by the error message, it appears the div is embedded where only phrasing content is allowed.

Using markup like this <p> ... <div> ... </div> ... </p> would generate this error, for example.

tthkbw commented 2 years ago

Thanks for the quick feedback. I am traveling the rest of this week, so can only take the time for a brief reply.

@mattgarrish - I think your hint may have led me to the problem, which, as I expected, is with my code.

Although I routinely create nested div elements, not all of them generate errors from eubcheck. I now see that those that do are nesting the div elements within italic elements, like this:

<div>some stuff<i>some italic stuff.<div>my added div</div></i></div>

That’s my bug, and I’ll fix it next week. I’ll report back then.

tthkbw commented 2 years ago

Okay, so I really couldn’t leave this alone. I found a quick fix in my code and I am now generating error-free epubs again.

Thanks for the help, and for epubcheck.

rdeltour commented 2 years ago

OK thanks for confirming! I'm closing this issue as invalid (not a bug in EPUBCheck).