Skip to content

backcompat child of mf2 root #11

@sknebel

Description

@sknebel

This question is to clarify what happens when a backcompat class appears as a child of an mf2 root, since both parser behavior and discussions have varying interpretations.

This markup is derived from what I today encountered on https://indieweb.org/events/2017-04-26-homebrew-website-club,

<span class="h-card vcard">
<a href="http://cherryreds.com">
  <span class="p-name fn p-org org">Cherry Red's</span>
</a>, 
<span class="adr">
  <span class="street-address p-street-address">88-92 John Bright St</span>, 
  <span class="p-locality locality">Birmingham</span>, 
  <abbr class="p-country-name country-name">UK</abbr>
</span></span>

spec reading

from the parsing specification:

  • parse a child element for microformats (recurse)
    • if that child element itself has a microformat ("h-*" or backcompat roots) and is a property element, add it into the array of values for that property as a { } structure, add to that { } structure:
      • value:
        • if it's a p-* property element, use the first p-name of the h-* child
        • else if it's an e-* property element, re-use its { } structure with existing value: inside.
        • else if it's a u-* property element and the h-* child has a u-url, use the first such u-url
        • else use the parsed property value per p-*, u-*, dt-* parsing respectively
  • else add found elements that are microformats to the "children" array

While the section for properties explicitly calls out microformats as "h-*" or backcompat roots, the one for children does not, but given the wording I'd still interpret it as meaning the same.

Also, the note backward compatibility details section says that backcompat classes are ignored in mf2 and mf2 classes in mf1 are ignored

without an intervening root class name

meaning a backcompat root can change processing to backcompat, and this is not explicitly limited to properties

parser results

Of the 4 main parsers supporting backcompat, there are 3 different results (unrelated bugs have been removed/ignored):

1A: child object

In what would also be my interpretation, mf2py and microformats-ruby recognize the adr class as a backcompat object and, since it doesn't have a property name, turn it into a child of the surrounding h-card:

{
  "items": [
    {
      "type": ["h-card"],
      "properties": {
        "name": ["Cherry Red's"],
        "org": ["Cherry Red's"],
        "url": ["http://cherryreds.com"]
      },
      "children": [
        {
		"type": ["h-adr"],
          "properties": {
            "street-address": ["88-92 John Bright St"],
            "locality": ["Birmingham"],
            "country-name": ["UK"]
          }
        }
      ]}]}

1B: ignore adr

php-mf2 ignores the adr and consequently parses the mf2 properties inside it as properties of the surrounding h-card (which is in this case the result the original author probably intended)

{
  "items": [
    {
      "type": ["h-card"],
      "properties": {
        "name": ["Cherry Red's"],
        "org": ["Cherry Red's"],
        "url": ["http://cherryreds.com"],
        "street-address": ["88-92 John Bright St"],
        "locality": ["Birmingham"],
        "country-name": ["UK"]
        }}]}

1C: apply backcompat rules =>as if "p-adr h-adr"

microformats-shiv (or more specifically, microformats-node based on it) seems to apply the backcompat rules for vcard.adr, turning the adr into the equivalent of p-adr h-adr. This IMHO clearly shouldn't be applied to a MF2 root like h-card, but there is an example in the test suite requiring this behavior(?!).

{
  "items": [
    {
	  "type": ["h-card"],
	  "properties": {
	    "name": ["Cherry Red's"],
		"org": ["Cherry Red's"],
		"url": ["http://cherryreds.com"],
		"adr": [
		  {
		    "value": "88-92 John Bright St, \n   Birmingham, \n   UK", 
			"type": ["h-adr"],
			"properties": {
			  "street-address": ["88-92 John Bright St"],
			  "locality": ["Birmingham"], "country-name":["UK"]
		    }
		  }]
		}}]}

(Side note: If the markup is changed from class="adr" to class="p-adr adr" (backcompat property value instead of child), microformats-shiv, mf2py and microformats-ruby produce the same result as 1C, whereas mf2-php flattens the "adr" property to a string)

Related material

In this issue, @aaronpk says:

Based on the mf2 wiki, I'm not totally clear whether this should be ignored or not: http://microformats.org/wiki/microformats2-parsing#note_backward_compatibility_details However, it was surprising to me that it's there, and I don't want it to show up in the mf2 parsed version.

and @gRegorLove seems to say that nested mf1 should be ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions