in reply to Re: Dancer and Template-Toolkit
in thread Dancer and Template-Toolkit

"<title> should be in a <head> element; <h1> and <h2> should be inside the <body>..."

Allow me to blow your mind... they already are!

Many HTML elements have optional closing tags. For example:

<p>Foo <p>Bar

When an HTML parser encounters the second opening <p> tag, it can infer that the first <p> element must have closed, because paragraphs cannot be legitimately nested. (Well, actually they can if you use the right interleaving elements, but that's another story...)

This is not just browsers being forgiving. It's part of the HTML spec; even allowed by the strict versions of HTML. (But not by XHTML obviously, which is an entirely different kettle of fish altogether.)

Now, here's the mindblowing bit. And it relies on you being able to divorce tags and elements a little in your mind. We've seen how an element can legitimately exist without a closing tag; it's also possible for an element to exist without an opening tag!

Given the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <title>Foo</title> <p>Bar</html>

... when a parser encounters the <title> tag, it infers that not only the <title> element has been opened, but that <html> and <head> have too. When it encounters <p> it infers that <head> must have closed (because <p> cannot be used within <head>) and <body> must have begun.

The Foo Bar document above is a complete, valid HTML 4.01 Strict document. Don't believe me?

spec ref

Now, you could argue that omitting optional start tags is bad style. I might even agree with you. But it's very, very common. (Hint: take a look at the content model for the <table> element.)

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name