Attribute references

John Gruber gruber at fedora.net
Sun Jan 9 20:56:23 EST 2005


european bob <bob at wolfwall.com> wrote on 01/09/05 at 7:00pm:

> Out of interest, how many times do you think you would apply the same
> attribute to a number of tags? I can think of class, plus perhaps some
> "work around CSS not being universal" attrs (cellspacing="0" ;), and
> that kind of thing, but I think the applicability it limited.

I think it would occasionally be useful to apply the same style
attribute to multiple elements, for one-time formatting style that
you don't want to add to your site-wide CSS file.

Or perhaps some JavaScript handler tomfoolery.


> So, your idea seems wrongly-huffman coded to me, if you see what I mean.
> If I was to make a guess, I would say the most often, someone would want
> to set a class. Second most often, and quite a way behind, setting an
> id. Some way behind that setting some other attribute.
> 
> So I would suggest a modified solution:
>         
>         ## Different way {different}
>           
>         Setting just a name should set the class. Otherwise, it might be
>         that we want to set *a reference*{ref:references}

That wouldn't work, because what if you wanted to produce:

    <h2>Different way {different}</h2>

I.e. you want literal {}-enclosed text at the end? In my proposal,
you will only run into a conflict if you do this *and* also have an
attribute reference definition using the same string, which is
unlikely enough not to bother me.

Whereas with your proposed syntax above, we'd be forcing people to
use backslash escapes to get those literal {}'s at the end.

This entire concept of adding tag attributes is a power-user
feature, so I want the onus to put on the people who need this
feature, not on the regular people who will never use it (most of
them might not even know what tag attributes are).


> If you see what I mean. Trying to make it less verbose in the common
> case, and differentiating between plural references (like class=) and
> singular references (like id=), and encouraging people to use to markup
> correctly.

But your suggestion is *more* verbose where it matters -- in the
text of the article itself. With my proposal, using this:

    ## This is the header  {a}

you add just three 'noise' characters to the end of the header. But the attribute reference could expand to a much longer class name:

    {a}: class="myClassNamesAreLongAndVerboseAndOccasionallyRendundant"

Put that definition at the bottom of the article, and it's out of
the way.


> It also means you can pull out warnings when references get
> incorrectly re-used: I know we've had the discussion about how much
> help to give a user on this list before, but I still don't like the
> idea of failing silently and expecting the user to memorise the
> references in use in a current document.

We could still write a Markdown lint-checker to check for duplicate
id attributes. In fact, it could even check the id attributes in raw
HTML tags. The problem with lint-checking or flagging errors as part
of Markdown itself is that where Markdown runs, there's no way to
alert the user, at least in apps like MT and WordPress.

> PS. If you're wondering where 'otherclass' was used; it wasn't. I was
> going to apply it to the "Setting.." paragraph, but couldn't figure out
> how - and also, how would you figure out that the {ref:references}
> applied to the em, and not the p?

I don't think you would. I'm thinking you'll only be able to apply
these things to block-level elements such as paragraphs, headers,
lists, and blockquotes. If you want an id or class assigned to a
span element such as em or strong, just use HTML.

-J.G.




More information about the Markdown-Discuss mailing list