Re: a more elegant fail on a kindlegen mobipocket pagebreak command, 2012-02-09 00:28 -0500:

> >   <mbp:pagebreak />
> it's the kindlegen command to throw a pagebreak
> when creating a mobipocket file (for the kindle)...


If you're able to, try <mbp:pagebreak></mbp:pagebreak>

Browsers don't pay any attention to "/>" in HTML pages. If you want to use
that syntax you need to use XHTML and namespaces.

> here's an example file with the offending outrage:
> >
> and the same file, without the devil pagebreaks:
> >
> now of course your validator should _raise_a_flag_
> when it encounters such a monstrosity, but lately,
> it has been choking completely, which is not good.

Choking how? You mean reporting "Element mbp:pagebreak not allowed as child
of element div in this context. (Suppressing further errors from this

> perhaps you could cause it to fail more elegantly?


The validator has a conforming HTML5 parser that parses markup in the same
way browser parsers do (in fact its the same parser used in Firefox).

When you feed to a browser, this is
what you end up with in the DOM:

DIV id="chunk8"
| #text: ↩
| HR
| | #text: ↩ ↩
| | A id="table_of_contents"
| | #text: ↩
| | P style="text-align:right;"
| | #text: ↩
| | A href="#pride_and_prejudice"
| | #text: <-
| | #text:     ↩
| | A href="#pride_and_prejudice"
| | #text: -c-
| | #text:     ↩
| | A href="#chapter_1"
| | #text: ->
| | #text:     
| | #text: ↩

That is, everything after the <mbp:pagebreak /> is made a child node of
that mbp:pagebreak element. That's because HTML parsers don't pay any
attention to XML-isms like "/>" (self-closing tag syntax). So browsers
don't see that as an empty element -- they see it as a element with a start
tag but no end tag.

The validator is doing the right thing here by trying to alert you to
something that is seriously broken in your source. If you're serving your
content at HTML and want to make sure it's going to work the way you
intend, don't use <mbp:pagebreak />. Otherwise use XHTML5 and namespaces.


Michael[tm] Smith

Received on Friday, 10 February 2012 08:34:29 UTC