From Microformats Wiki
Jump to navigation Jump to search

include pattern brainstorming

brainstorming to improve or extend the include-pattern.

alternatives to using a or object

Here are possible variations on the include pattern, attempting to resolve issues of accessibility (with empty anchors) and server load (with object).

Non-Verbose Class-Based Solution

(Originally suggested by Toby Inkster, based on an earlier proposal by Andy Mabbett)

An alternative way of implementing the include pattern in a less verbose, and hopefully more accessible manner.

 <p>We have three branches in <span class="locality" id="ldn">London</span>,
 including our head office in <span class="locality" id="ken">Kensington</span>:</p>
   <li class="adr #ldn">
     <span class="street-address">123 Oxford Street</span>
   <li class="adr #ken #ldn">
     <span class="street-address">5 Kensington High Street</span>
   <li class="adr #ldn">
     <span class="street-address">1 Pall Mall</span>

The order of the space-delimited class attributes should be considered significant -- that is, in <foo class="bar #baz"> the content referred to by #baz is logically included as the last child of the <foo> element, but in <foo class="#baz bar">, it is logically included as the first child. (See below for an example where the included element should occur in the middle of the element content.)

Yes, the hash mark is valid in the class attribute, though rarely used because it won't work with CSS 1 selectors.

If people can find real-life uses of the hash character in existing sites that would conflict with this proposed usage pattern, then perhaps another character could be used. I rather like '@foo', or maybe even a combination such as '@#foo'.

Including data in the middle of an element

Above, the examples show how an element can be logically included as the first or last child of another element. For including data into the middle of an element, we need to be a tiny bit more verbose and insert a dummy element (in this case a <span> element) where the included content should go:

 <p>Our head office is in <span id="ldn" class="locality">London</span> at:
 <p class="adr">
   <span class="street-address">5 Kensington High Street</span><br>
   <span class="#ldn"></span>
   <span class="postal-code">SW7 1AA</span>

problems with ordered ids in class

Two problems:

1. class is an unordered set of values per HTML4. introducing ordering is a non-starter both from a violation of HTML4 spec perspective and likely requiring of rewriting HTML4 parsers to maintain an ordering where they currently don't.

A reading of HTML 4.01, section 7.5.2 doesn't seem to claim that the class list is unordered.

It does claim that it's a "set" of class names, and in mathematical parlance sets are unordered by definition, and must not contain duplicates, but it's unlikely that the framers of the HTML 4.01 spec intended the world "set" to be interpreted in that way -- far more likely they were referring to the layman's definition of the word.

As far as parsers are concerned, DOM Level 2 HTML provides as "className" property as part of the HTMLElement interface, which is either directly used or is inherited by all DOM element nodes. The className is a string exactly reflecting the contents of the HTML class attribute, so should reflect their original order.

And any non-DOM, naive SGML or XML parser that encounters a class attribute will just parse it as a plain old string anyway, so the order should be retained.

TobyInk 08:34, 5 Feb 2008 (PST)

2. inclusion of arbitrary data (#baz) in the class attribute is a documented anti-pattern. Tantek

This anti-pattern is only mentioned as a subheading to the more general anti-pattern of invisble metadata. My suggested pattern for inclusions does not hide metadata -- it merely references metadata elsewhere on the page. It is no more guilty of hiding metadata than any other suggested include pattern, so I fail to see how this is relevant.

TobyInk 08:36, 5 Feb 2008 (PST)

Simple class name

<foo id="birmingham" class="locality">Birmingham</foo>


<foo class="adr includes-birmingham">[...]</foo>

Some other possible variants are:

<foo class="adr birmingham">[...]</foo>


<foo class="adr part-microformat birmingham">[...]</foo>


<foo class="adr use-birmingham">[...]</foo>


<foo class="adr uses-birmingham">[...]</foo>


<foo class="adr include-birmingham">[...]</foo>


<foo class="adr locality-birmingham">[...]</foo>


<foo id="birmingham">Birmingham</foo>
<foo class="adr locality-birmingham">[...]</foo>

(originally suggested by Andy Mabbett in < et seq.)

problems with arbitrary id values in class attributes

In short: similar to problems with ordered ids in class, inclusion of arbitrary data (birmingham) in the class attribute is a documented anti-pattern.

Longer: The value of an id attribute on an element is essentially an arbitrary string used to uniquely identify that element in the context of the document. Thus the re-use of such an arbitrary string (e.g. "birmingham") in a class attribute is an instance of including arbitrary data in the class attribute, which is a documented anti-pattern.


  • In this proposal, the class name is not "arbitrary data", since it uses a semantically valid IDs; and is semantically logical. In the cited page the use of data in class names is deprecated as "another form of invisible metadata". This proposal involves no more "invisible metadata" than do the existing include patterns. Andy Mabbett 00:52, 4 Feb 2008 (PST)
    • existing include patterns use href and data (not class) attributes which are both of type URI to point to a fragment identifier. arbitrary links are proper semantic use of URI attributes per HTML4. however in a class attribute, arbitrary links are no more than arbitrary data, and are thus an example of the documented anti-pattern. (Unsigned comment by Tantek)
      • The fragment identifier is not data. Well, OK, it is data in the sense that virtually everything is data, but, in the example above, the link itself is not address data -- it's a pointer to data... information about where the real data might be found... it's metadata. TobyInk 07:42, 6 Feb 2008 (PST)

Use @ to Reffernce Id's

Don't "include" your data, you could perhaps just reference them.

<foo id="me" class="fn">Fred</foo>
<bar class="me@url"></bar>

parsers instead of replacing data can then just append their data?

Suggested on Microformats Discuss:

problems with using at ref to id


Related Pages