Re: nested SGML comments

	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
	<title></title>
	<p><!-- <!-- --> </p> <div> --></p>
	
	validates (so i think SGML allows nesting of comments)
	
No it doesn't.  No way, not nohow.
What it *does* allow is repeated --xxx-- groups within an unnested comment.
I've copied the line with the comment and shown how SGML understands it.
	<p><!-- <!-- --> </p> <div> --></p>
             AAAAAAA BBBBBBBBBBBBBBBBB

Here are the actual rules from the SGML standard:

"[91] comment declaration =
          mdo, (comment, (s|comment)*)?, mdc
 [92] comment =
          com, SGML character*, com
 No markup is recognized in a comment,
 other than the com delimiter that terminates it."

where
 mdo = '<!', mdc = '>', com = '--', and s means any layout character.

Note in particular the explicit warning that markup (other than --)
is NOT recognised within a comment.

Note also that XML forbids having multiple comments in a comment
declaration, and that some HTML implementations have got their
comment tokenising wrong.

	Tidy makes the following out of this:
	[deleted]	
	This does not match the parse tree of an SGML parser.
	
Which one?  Nested comments are not allowed by SGML in general or by
HTML in particular.  Your particular example would work in *some* HTML
implementations largely by accident.  Tidy has warned you that you
have trouble here, and it is right about that.

Received on Sunday, 19 November 2000 18:12:05 UTC