Re: Validator problem

Frank McCown <fmccown@harding.edu>, 2017-10-05 13:30 -0500:
> Archived-At: <http://www.w3.org/mid/CAFHYihNBPYsoiJdUuqau_0KeaF80svXWg3TN8+cZL0ZGctnYAw@mail.gmail.com>
> 
> <!DOCTYPE html>
> <html>
> <head>
> <title>UEF</title>
> <h1>test</h1>
> </html>
>
> I believe your HTML validator (https://validator.w3.org/nu/#textarea) has a
> problem.  The HTML below passed with no errors despite the fact that
> </head> is missing.  According to the HTML5 specs:
>
>     A head element's end tag can be omitted if the head element is not
>     immediately followed by ASCII whitespace or a comment.
> 
> Since <head> is followed by whitespace, </head> should be required.

The rule as written isn’t about the <head> start tag being followed by
whitespace. It’s instead about the head *element* being followed by
whitespace. So the whitespace after the <head> start tag isn’t relevant.

What that rule is saying is probably more clear if you instead look at an
example that has a comment:

  <html>
  <head>
  <title>UEF</title>
  <!-- this comment is part of the head -->
  <h1>test</h1>
  </html>

The following is a serialization of exactly how that gets parsed by an HTML
parser that conforms to the parsing algorithm in the spec:

  <html><head>
  <title>UEF</title>
  <!-- this comment is part of the head -->
  </head><body><h1>test</h1>

  </body></html>

Incidentally, notice how that results in no space after the head element
and before the body element. But as far as the comment, from that you can
see what the rule in the spec is saying is, if you want that comment to be
after the head element but before the body element, then the head element
must have a </head> end tag:

  <html>
  <head>
  <title>UEF</title>
  </head>
  <!-- this comment is between the head and body -->
  <h1>test</h1>
  </html>

The following is a serialization of exactly how that gets parsed by an HTML
parser that conforms to the parsing algorithm in the spec:

  <html><head>
  <title>UEF</title>
  </head>
  <!-- this comment is part of the head -->
  <body><h1>test</h1>

  </body></html>

The same goes for case of whitespace that the rule mentions: If you want
the parsed result to have whitespace after the head element, then you must
include a </head> end tag with whitespace after it:

  <html>
  <head>
  <title>UEF</title>
  </head>
  <h1>test</h1>
  </html>

The following is a serialization of exactly how that gets parsed by an HTML
parser that conforms to the parsing algorithm in the spec:

  <html><head>
  <title>UEF</title>
  </head>
  <body><h1>test</h1>

  </body></html>

Without that, you otherwise end up with </head><body>, no whitespace between.

-- 
Michael[tm] Smith https://people.w3.org/mike

Received on Saturday, 7 October 2017 11:02:05 UTC