« The Slideshow Must Go On | Main | Understanding HTTP PUT »

HTML 5 And The Hear-Write Web

HTML 5 working draft defines a parsing algorithm which is robust enough that it will not break for the most common types of errors. Many computing engineers and Web designers think that this feature encourages bad quality for documents. Point taken. But let's look a bit further at what proposes HTML 5 in terms of input and output.

How do we understand typos. I do mistakes very often. English is not my mother tongue. I try to fix spelling mistakes as much as possible. Still, my English grammar is still behind. Oh, not looking for any excuses, I do mistakes in French too. But I'm glad that our brains have a very robust parsing mechanism which helps us to recover from broken sentences (bad spelling and clumsy grammar). Just imagine for the experiment, that your brain was not able to parse any sentences that would not be grammatically correct. How many sentences in our daily conversation are 100% correct? Not that much.

At W3C, we take meetings minutes (a lot) of discussions happening over a phone. During these teleconferences, there are people from different nationalities, different accents, different levels of English and on top of that in different time zones (fatigue). Still the scribe (minute taker) writes down, most of the time, correct English sentences after parsing them. The scribe creates a serialization of what he heard, but modifies it to be correct.

An HTML 5 Tidy library could do the same thing. It could parse a broken document and create a DOM following the HTML 5 parsing algorithm. Then it could serialize it (writes it down) following the HTML 5 content model. That would create a conformant HTML 5 document.

This is an important part of the process. What you hear is not what you write. You are stricter, once you have recovered the meaning. The same way what the HTML 5 Tidy library has parsed is not what it will serialize. Let's take a practical example with the infamous center element.

<!DOCTYPE html>
<html>
  <title>a broken document</title>
  <center><p>I want to be in the center of the page.</p></center>
</html>

The innerHTML view (using HTML 5 Live DOM viewer) is:

<!DOCTYPE HTML>
<html>
  <head>
    <title>a broken document</title>
  </head>
  <body>
    <center><p>I want to be in the center of the page.</p></center>
  </body>
</html>

But the document will be invalid and the message given by the experimental HTML 5 validator instance will be

Validation Output:  1 Error
#  Error  Line 4, Column 7: The center element is obsolete..

Why? Because nowhere in the content model of HTML 5, the center element is defined. You can't write an HTML 5 conformant document containing the center element. An HTML 5 Tidy library would emit only elements which are compatible with the HTML 5 content model. In this case that could be

<!DOCTYPE HTML>
<html>
  <head>
    <title>a broken document</title>
  </head>
  <body>
    <p>I want to be in the center of the page.</p>
  </body>
</html>

Some people will argue that everyone will want different rules. Indeed that is possible. Some will want to have double quotes around attributes, some single quotes. And if we take into account the set of documents which have complex mixed markup, it will indeed create a lot of headaches. But it's why I think it would be interesting to define a set of basic rules for emitting HTML 5 after it has been parsed.

Some might propose solutions of the following type for the center element.

<!DOCTYPE HTML>
<html>
  <head>
    <title>a broken document</title>
  </head>
  <body>
    <p style="text-align:center;">
      I want to be in the center of the page.
    </p>
  </body>
</html>

Daniel Glazman proposed recently something quite similar for HTML attributes, inline style or style rules.

Are there any engineers which would be ready to take the challenges of designing an HTML 5 Tidy Library (and the canonic rules to fix the output) using the content model of HTML 5? I showed recently that there will be less document validating with the HTML 5 doctype than with their current doctype. Henri Sivonen rightly commented that HTML 5 content model was stricter than previous versions of HTML. This will not leverage the adoption of conformant HTML 5.

An HTML 5 Tidy Library (even not perfect) would help people to move forward. If there are no benefits, people will continue to use HTML 4.01 and/or XHTML 1.0 because, in the end it doesn't matter,

Filed by Karl Dubost on September 26, 2008 6:44 AM in HTML, Opinions and Editorial, Technology 101, Tools
| | Comments (10) | TrackBacks (0)

Comments

estelle # 2008-09-26

in the case of redefining the CENTER element to be an inline style, the question arises as to the cascade. My suggestion for such an example would be

<!DOCTYPE HTML>
<html>
  <head>
    <title>a broken document</title>
  </head>
  <body>
    <div style="text-align:center;">
      <p>I want to be in the center of the page.</p>
    </div>
  </body>
</html>

Suggestion: convert deprecated inline elements, such as FONT, to SPANs, and block level elements, such as CENTER, to DIVs.

S # 2008-09-28

Couldn't you just write:

<!DOCTYPE HTML>
<html>
  <head>
    <title>a broken document</title>
  </head>
  <body>
    <p align="center">
      I want to be in the center of the page.
    </p>
  </body>
</html>

Or is that obsolete too?

Blair # 2008-10-03

The align attribute is deprecated in HTML 4.01. Most modern HTML viewers do recognize it and will render your example as intended (and will doubtless continue to do so for the foreseeable future).

But with the movement to use HTML for structure and CSS to control the actual presentation, creating a style attribute is preferable.

salzi # 2008-10-17

I would love to get this back:

<!DOCTYPE HTML>
<html>
  <head>
    <title>a broken document</title>
  </head>
  <body>
    <p>I want to be in the center of the page.</p>
  </body>
</html>

In my point of view, that is the only clean way. As you said before, everyone will want different rules. The discussion about convert deprecated element and so on, will never end.

With this solution, you would get HTML 5 Code, nothing more, nothing less. If the reslut doesn't fit you expectances, you can find out what is missing and find a solution for it (i.e. using stlye="" attributes)

Lee Goddard # 2008-10-27

To avoid losing potentially-significant mark-up, I would appreciate an option to allow inline elements such as 'font' to become spans, perhaps with a class attribute of 'font.' Equally, block-level elements might become divs.

David # 2008-11-12

I would prefer to get the clean html 5 markup back with no presentation (styles, or otherwise) in it at all. If important markup will be removed I can always copy the old markup before running tidy.

Karl Dubost Author Profile Page # 2008-11-13

I can see the benefits of translating the style information or to just get the clean markup. I guess for some people, the step for fixing their code without the style information will be too high. For example, if you remove all center and do not replace them by anything, the layout will be destroyed and they will feel that the Web standards are inferior to their own choices.

steven christopher # 2008-11-22

i would prefer the font's to become family font src="......./...../ etc the "pre" tags to become "fixed"(fxd) body background to become = "bbgsrc="color" or "img".html etc do away with the <div> tags and just use <br /> also it's about time we do away with all the old html and stick to 3.2 and upwards. out with old ! in with the new !

Larry Masinter # 2009-05-19

It makes more sense to specify first what writers should write, and then secondly give advice about what hearers are expected to understand to be compatible with what is currently written.

The current HTML5 specification intentionally doesn't do that: it defines how hearers are supposed to listen, and, as an afterthought, gives some restrictions as to what should be written.

Izek # 2009-06-16

DIVs don't like to center block level content just so you know (Such as other DIVs.) Text-align:center won't always work.

Leave a comment

Note: this blog is intended to foster polite on-topic discussions. Comments failing these requirements and spam will not get published. Please, enter your real name and email address. Every individual comment is reviewed by the W3C staff. This may take some time, thank you for your patience.

You can use the following HTML markup (a href, b, i, br/, p, strong, em, ul, ol, li, blockquote, pre) and/or Markdown syntax.

Your comment


About you

This blog is written by W3C staff and working group participants,
 and maintained by Coralie Mercier.
Authorized parties may log in to create a new entry.
Powered by Movable Type, magpierss and a lot of Web Technology