WebPlatformTest / HTML5test

How well does your browser support HTML5?
https://html5test.com
MIT License
995 stars 193 forks source link

Block-wrapping <a> element #37

Closed westonruter closed 14 years ago

westonruter commented 14 years ago

Another useful Parsing rules test would be whether an <a> element can wrap block elements.

<a href="...">
    <h1>Info</h1>
    <p>This is interesting.</p>
</a>

Old HTML parsers may parse this as:

<a href="..."></a>
<h1>Info</h1>
<p>This is interesting.</p>
<!-- Ignored: </a>-->
KieranP commented 14 years ago

The code you posted for wrapping a <a /> around <h1 /> is invalid HTML.

The correct way according to the standards is to do this:

<h1><a href="...">info</a></h1>
<p><a href="...">This is interesting.</a></p>
NielsLeenheer commented 14 years ago

Actually, the whole point is that this construction is allowed in HTML5. And a HTML5 parser should create a DOM structure with an 'a' element as parent and 'h1' and 'p' as children.

westonruter commented 14 years ago

"The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links). This example shows how this can be used to make an entire advertising block into a link:"

http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-a-element

NielsLeenheer commented 14 years ago

I'm not sure if we should include this test in html5test.com. This construct is new to the HTML5 specification, but in this case the specification follows common behavior. Browsers already allow a as a block level element and all browsers would pass this this.

KieranP commented 14 years ago

westonruter, I stand corrected! Thank you for the link. HTML 5 has some nicer surprises in store :-)