Alternate syntax for defining class attribute

View: New views
7 Messages — Rating Filter:   Alert me  

Alternate syntax for defining class attribute

by T.J. Crowder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

First off, thank you for all of your work hammering out HTML5.
Greatly appreciated!

I have a suggestion which may be too late for HTML5 or not in keeping
with the philosophy, but I'll give it a go:

We use the class attribute a *lot*.  To save our poor fingers, not to
mention reduce document sizes, would it be possible to introduce an
alternate syntax for simple situations (one class) mirroring the basic
CSS class selector syntax?  E.g., this:

    <div class='nifty'>nifty stuff here</div>

becomes

    <div.nifty>nifty stuff here</div>

Seems to me this is easily parsed and not a significant burden to
implementors, whereas I think most authors would be thrilled to have
the syntax line up with CSS and to stop typing "class='" all over the
place.

This is an alternate, not a replacement.  If one needs multiple class
names, for example, one would use the original syntax.  Now, it would
be nice to be able do something like this:

    <div."nifty stuff">nifty stuff here</div>

....if people who know more about parsers than I (their numbers are
legion) say that the optional quotes aren't hard to deal with.

Obviously the caveat would be that if you send this alternate form to
a UA that doesn't understand HTML5, it's not going to be a happy
bunny.  Caveat author.

Alternatively (no pun), a less easily-parsed version that doesn't seem
to break the small number of UAs I tried (all browsers: IE7, FF3,
Safari3win, Opera9, Chrome2) too badly is to allow whitespace between
the tag and the dot:

    <div .nifty>nifty stuff here</div>

Older browsers wouldn't see the class name, obviously, but they seem
to mostly ignore the invalid attribute.  I don't like this becaue it
looks like a parsing nightmare to me, although as I said, I'm not a
parser guy.

Apologies if this is a duplicate.  A couple of archive searches didn't
turn it up, but there are probably 18 ways to phrase this.

Thanks for listening,
--
T.J. Crowder
tj / crowder software / com



Re: Alternate syntax for defining class attribute

by Max Romantschuk-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

T.J. Crowder wrote:

> We use the class attribute a *lot*.  To save our poor fingers, not to
> mention reduce document sizes, would it be possible to introduce an
> alternate syntax for simple situations (one class) mirroring the basic
> CSS class selector syntax?  E.g., this:
>
>     <div class='nifty'>nifty stuff here</div>
>
> becomes
>
>     <div.nifty>nifty stuff here</div>

While the suggested syntax would undoubtedly be handy, I believe you're
attacking the wrong problem.

The class attribute is seldom needed when the CSS selectors are used
correctly withing a well structured document. Any browser that would
support a feature like this already supports a wide array of CSS
selectors allowing you to target any element in the document with only a
fraction having a dedicated class.

I suggest reading up on CSS selectors:
http://www.w3.org/TR/CSS2/selector.html


Once you have realized that you don't really need classes that much it
makes little or no sense to have a dedicated special case (which would
complicate the parser a great deal) just as a shorthand for the class
attribute.

I suspect the easiest solution is using a suitable tool to set up a
keyboard macro for adding 'class=""' into your source.


   Regards,
Max

--
        Max Romantschuk
        max@...
http://max.romantschuk.fi/



Re: Alternate syntax for defining class attribute

by T.J. Crowder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Max,

I'm quite familiar with CSS selectors, and I disagree.  Classes still
come up a lot.  I'm still making the suggestion.

-- T.J.



2009/8/10 Max Romantschuk <max@...>:

> T.J. Crowder wrote:
>>
>> We use the class attribute a *lot*.  To save our poor fingers, not to
>> mention reduce document sizes, would it be possible to introduce an
>> alternate syntax for simple situations (one class) mirroring the basic
>> CSS class selector syntax?  E.g., this:
>>
>>    <div class='nifty'>nifty stuff here</div>
>>
>> becomes
>>
>>    <div.nifty>nifty stuff here</div>
>
> While the suggested syntax would undoubtedly be handy, I believe you're
> attacking the wrong problem.
>
> The class attribute is seldom needed when the CSS selectors are used
> correctly withing a well structured document. Any browser that would support
> a feature like this already supports a wide array of CSS selectors allowing
> you to target any element in the document with only a fraction having a
> dedicated class.
>
> I suggest reading up on CSS selectors:
> http://www.w3.org/TR/CSS2/selector.html
>
>
> Once you have realized that you don't really need classes that much it makes
> little or no sense to have a dedicated special case (which would complicate
> the parser a great deal) just as a shorthand for the class attribute.
>
> I suspect the easiest solution is using a suitable tool to set up a keyboard
> macro for adding 'class=""' into your source.
>
>
>  Regards,
> Max
>
> --
>       Max Romantschuk
>       max@...
> http://max.romantschuk.fi/
>


Re: Alternate syntax for defining class attribute

by Ryan Roberts-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi T.J.

HTML5 aims to be backward compatible as far as possible, but your suggest would not be backward compatible. The only benefit I can see here is saving a few characters, the suggestion also breaks from the standard HTML syntax. The negative implications of implementing this suggestion would far outweigh any benefits.

Sorry but I can't see it being taken on board.

Cheers,
Ryan



T.J. Crowder wrote:
Hello,

First off, thank you for all of your work hammering out HTML5.
Greatly appreciated!

I have a suggestion which may be too late for HTML5 or not in keeping
with the philosophy, but I'll give it a go:

We use the class attribute a *lot*.  To save our poor fingers, not to
mention reduce document sizes, would it be possible to introduce an
alternate syntax for simple situations (one class) mirroring the basic
CSS class selector syntax?  E.g., this:

    <div class='nifty'>nifty stuff here</div>

becomes

    <div.nifty>nifty stuff here</div>

Seems to me this is easily parsed and not a significant burden to
implementors, whereas I think most authors would be thrilled to have
the syntax line up with CSS and to stop typing "class='" all over the
place.

This is an alternate, not a replacement.  If one needs multiple class
names, for example, one would use the original syntax.  Now, it would
be nice to be able do something like this:

    <div."nifty stuff">nifty stuff here</div>

....if people who know more about parsers than I (their numbers are
legion) say that the optional quotes aren't hard to deal with.

Obviously the caveat would be that if you send this alternate form to
a UA that doesn't understand HTML5, it's not going to be a happy
bunny.  Caveat author.

Alternatively (no pun), a less easily-parsed version that doesn't seem
to break the small number of UAs I tried (all browsers: IE7, FF3,
Safari3win, Opera9, Chrome2) too badly is to allow whitespace between
the tag and the dot:

    <div .nifty>nifty stuff here</div>

Older browsers wouldn't see the class name, obviously, but they seem
to mostly ignore the invalid attribute.  I don't like this becaue it
looks like a parsing nightmare to me, although as I said, I'm not a
parser guy.

Apologies if this is a duplicate.  A couple of archive searches didn't
turn it up, but there are probably 18 ways to phrase this.

Thanks for listening,
--
T.J. Crowder
tj / crowder software / com


  


--
Web Designer


Web: http://ryanroberts.co.uk

Email: hello@...

Phone: 07759 917 964


Re: Alternate syntax for defining class attribute

by Ian Hickson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 9 Aug 2009, T.J. Crowder wrote:
>
> First off, thank you for all of your work hammering out HTML5. Greatly
> appreciated!

Thanks!


> I have a suggestion which may be too late for HTML5 or not in keeping
> with the philosophy, but I'll give it a go:
>
> We use the class attribute a *lot*.  To save our poor fingers, not to
> mention reduce document sizes, would it be possible to introduce an
> alternate syntax for simple situations (one class) mirroring the basic
> CSS class selector syntax?  E.g., this:
>
>     <div class='nifty'>nifty stuff here</div>
>
> becomes
>
>     <div.nifty>nifty stuff here</div>
>
> Seems to me this is easily parsed and not a significant burden to
> implementors, whereas I think most authors would be thrilled to have the
> syntax line up with CSS and to stop typing "class='" all over the place.

We've looked at doing this before, but it has a very poor backwards-
compatibility story, unfortunately.

I would encourage you to find ways to avoid using class attributes, e.g.
by writing selectors that are based on the structure of the document. For
example, instead of:

   <h1>...</h1>
   <p class="firstp">...</p>

   p.firstp { ... }

...do something like:

   <h1>...</h1>
   <p>...</p>

   h1 + p { ... }


> Alternatively (no pun), a less easily-parsed version that doesn't seem
> to break the small number of UAs I tried (all browsers: IE7, FF3,
> Safari3win, Opera9, Chrome2) too badly is to allow whitespace between
> the tag and the dot:
>
>     <div .nifty>nifty stuff here</div>
>
> Older browsers wouldn't see the class name, obviously, but they seem to
> mostly ignore the invalid attribute.  I don't like this becaue it looks
> like a parsing nightmare to me, although as I said, I'm not a parser
> guy.

It wouldn't be that hard to parse, but it would only say you a 5
keystrokes, and all the old browsers would miss the class attribute, so
it's not really worth it, I think.

Cheers,
--
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: Alternate syntax for defining class attribute

by T.J. Crowder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ian,

Thanks for the considered answer.

> We've looked at doing this before, but it has a very poor backwards-
> compatibility story, unfortunately.

Yes, again, I did make the point in my original post that using this
shorthand form would very much be a "caveat author" (author beware)
situation -- the effect in older UAs will not be as desired.  Very
much like the new tags.  I frankly wouldn't expect to get much use out
of this new shorthand form for a good 3-4 years while compliance comes
up -- but in 3-4 years, it would be quite nice to have, hence
suggesting it now.

> I would encourage you to find ways to avoid using class attributes, e.g.
> by writing selectors that are based on the structure of the document.

Yes, naturally one does that wherever possible.  In the real,
pragmatic world of interactive web applications, it's simply not
always possible, and sometimes not preferred for other reasons.

> It wouldn't be that hard to parse, but it would only say you a 5
> keystrokes...

Which is to say, frequently, half the total.  I think 50% gains are
worth pursuing.  But even more so, the alignment with CSS syntax is
very attractive and natural.

-- T.J.

2009/8/15 Ian Hickson <ian@...>

>
> On Sun, 9 Aug 2009, T.J. Crowder wrote:
> >
> > First off, thank you for all of your work hammering out HTML5. Greatly
> > appreciated!
>
> Thanks!
>
>
> > I have a suggestion which may be too late for HTML5 or not in keeping
> > with the philosophy, but I'll give it a go:
> >
> > We use the class attribute a *lot*.  To save our poor fingers, not to
> > mention reduce document sizes, would it be possible to introduce an
> > alternate syntax for simple situations (one class) mirroring the basic
> > CSS class selector syntax?  E.g., this:
> >
> >     <div class='nifty'>nifty stuff here</div>
> >
> > becomes
> >
> >     <div.nifty>nifty stuff here</div>
> >
> > Seems to me this is easily parsed and not a significant burden to
> > implementors, whereas I think most authors would be thrilled to have the
> > syntax line up with CSS and to stop typing "class='" all over the place.
>
> We've looked at doing this before, but it has a very poor backwards-
> compatibility story, unfortunately.
>
> I would encourage you to find ways to avoid using class attributes, e.g.
> by writing selectors that are based on the structure of the document. For
> example, instead of:
>
>   <h1>...</h1>
>   <p class="firstp">...</p>
>
>   p.firstp { ... }
>
> ...do something like:
>
>   <h1>...</h1>
>   <p>...</p>
>
>   h1 + p { ... }
>
>
> > Alternatively (no pun), a less easily-parsed version that doesn't seem
> > to break the small number of UAs I tried (all browsers: IE7, FF3,
> > Safari3win, Opera9, Chrome2) too badly is to allow whitespace between
> > the tag and the dot:
> >
> >     <div .nifty>nifty stuff here</div>
> >
> > Older browsers wouldn't see the class name, obviously, but they seem to
> > mostly ignore the invalid attribute.  I don't like this becaue it looks
> > like a parsing nightmare to me, although as I said, I'm not a parser
> > guy.
>
> It wouldn't be that hard to parse, but it would only say you a 5
> keystrokes, and all the old browsers would miss the class attribute, so
> it's not really worth it, I think.
>
> Cheers,
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: Alternate syntax for defining class attribute

by Ian Hickson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, 15 Aug 2009, T.J. Crowder wrote:

> >
> > We've looked at doing this before, but it has a very poor backwards-
> > compatibility story, unfortunately.
>
> Yes, again, I did make the point in my original post that using this
> shorthand form would very much be a "caveat author" (author beware)
> situation -- the effect in older UAs will not be as desired.  Very much
> like the new tags.  I frankly wouldn't expect to get much use out of
> this new shorthand form for a good 3-4 years while compliance comes up
> -- but in 3-4 years, it would be quite nice to have, hence suggesting it
> now.

I think it would take a lot longer than 4 years, but in the meantime we'd
have quite an unfortunate situation with respect to some browsers having
very different results than others, etc.


> > It wouldn't be that hard to parse, but it would only save you a 5
> > keystrokes...
>
> Which is to say, frequently, half the total.  I think 50% gains are
> worth pursuing.  But even more so, the alignment with CSS syntax is very
> attractive and natural.

I think what would be helpful would be to make a JS library that fakes
this (by searching for elements with attributes that start with "." and
adding them to the class="" attribute), and seeing if it gets adoption.
That would provide interesting information for future developers of HTML.

--
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'