oreillymedia / HTMLBook

Let's write books in HTML!
http://oreillymedia.github.io/HTMLBook
MIT License
646 stars 99 forks source link

Headings: HTML5 vs HTMLBook #215

Open dac514 opened 6 years ago

dac514 commented 6 years ago

We hope to start using HTMLBook in a WordPress application where everything in between <div class="content"> tags is generated by WordPress.

This document is valid HTML5:

<!DOCTYPE html>
<head>
    <title>HTMLBook Sample</title>
    <meta name="HTMLBook Sample" content="text/html; charset=utf-8"/>
</head>
<body data-type="book" class="book" id="htmlbook">
<section data-type="chapter">
    <header>
        <h1>HTMLBook</h1>
    </header>
    <div class="content">
        <h1>WordPress Post</h1>
        <p>The User Is Doing Things</p>
        <h1>WordPress Post</h1>
        <p>The User Is Doing Things</p>
    </div>
</section>
</body>
</html>

(Tested here: https://html5.validator.nu/)

The same document with an extra:

<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.w3.org/1999/xhtml ../schema/htmlbook.xsd"
      xmlns="http://www.w3.org/1999/xhtml">

In the header is not valid HTMLBook. It complains about the second <h1>

element h1: Schemas validity error : Element '{http://www.w3.org/1999/xhtml}h1': This element is not expected."

I understand why it is invalid in HTMLBook but... the HTML5 spec "encourages" authors to use "headings of the appropriate rank" instead of h1 everywhere. An encouragement is not a normative requirement.

Is there something we can do to loosen the headings validation between a given div tag?

caraya commented 6 years ago

div is not a new container element. The spec says this about div:

Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of the div element leads to better accessibility for readers and easier maintainability for authors.

Maybe change it to section, aside or article if you have a choice.