Hi, I’ve come across a weird HTML coding issue with the Code Block style. I didn’t see anything about it in the forum.
In the book I’m working on, I use Code block to format chat dialogue. When I was compiling my book, EPubCheck gave me a ton of errors, all relating to the sections of said chat. They look like this:
ERROR (RSC-005) at “rehuman_codeblocktest.epub/OPS/body.xhtml” (line 48, col 6):
Error while parsing file: element “pre” 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”, “em”, “embed”, “epub:switch”, “i”, “iframe”, “img”, “input”, “ins”, “kbd”, “label”, “link”, “map”, “mark”, “meta”, “meter”, “ns1:math”, “ns2:svg”, “object”, “output”, “picture”, “progress”, “q”, “ruby”, “s”, “samp”, “script”, “select”, “slot”, “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 element from another namespace
It took me a while, but I think I figured out the issue.
When I checked the HTML in Calibre, I noticed this output for a testing section of the Code Block style:
<pre><code><span class="code-block">Testing testing testing</span>
<pre><code>One two three</code></pre>
<pre><code>Four five six</code></pre>
In the first line of the text, there is the Code Block span (I don’t know why it’s only one line, though I suppose perhaps the formatting assumes a long, unbroken string of code, and not several lines?), but it doesn’t close the “pre” and “code” tags on that line, unlike the other lines. I think EPubCheck is freaking out because it then thinks the SECOND “pre” tag is nested.
I couldn’t figure out any other way to fix it aside from editing the raw HTML. I tried making a new style that had the same preformatted text font, but it doesn’t output the font in the final epub. really like how the preformatted text looks in my book, and I don’t mind fixing the HTML, but I wanted to pass the issue along!
I otherwise very much love Scrivener, thanks for making it! ![]()