Re: Comment syntax

On Tue, 2012-09-04 at 14:03 +0800, Kang-Hao (Kenny) Lu wrote:
> (12/09/04 0:36), Liam R E Quin wrote:
> I meant an agent that outputs XHTML. Perhaps I should have been more
> clear. For example, HTML tidy currently converts
>   //test
>   alert('hello word');
> to
>   //test alert('hello word');
> in @onload, which is obviously a mistake.
It's not obvious to me that it's a mistake, although I agree it's likely
to cause problems.

>  It can instead either
>   1. remove //-style comments in on* attributes.
>   2. convert line feeds to character references as suggested by the
> polyglot document[1].

I'd suggest filing a bug against tidy here.

> > If we'd been designing XML as an HTML replacement we might have
> > specified the language differently, but that wasn't our goal :-)
> > 
> > But since, as you point out, // doesn't work for JavaScript in XHTML,
> > maybe it's OK that it won't work for CSS either...
> It still kind of depends on the data. If all XHTML agents gracefully do
> 2. above then this would not have been an issue at all. But that doesn't
> seem to be the case...

It's harder to get it to happen than you might think. In your example
above, a conforming SGML or XML parser would never see the newline in
the onload attribute, so it obviously can't add one on serialization. A
newline is treated sa a space on input. So you can't easily get one
there for tidy unless you use a character reference.

The problem for CSS here is that // isn't going to be reliable inside
attributes. It may comment out more than authors expect. It already
doesn't do what you might expect in CSS files:

div {
  // color: red; background: yellow;
  margin-left: 12pt;

Here, background: yellow is not commented out today.

Making // comment to end of line would presumably be a breaking,
incompatible change.

Anyway, enough from me on this :)


Liam Quin - XML Activity Lead, W3C,
Pictures from old books:
Ankh: freenode/#xml
Co-author, 5th edition, "Beginning XML", Wrox, July 2012

Received on Tuesday, 4 September 2012 06:32:44 UTC