microformats / microformats2-parsing

For collecting and handling issues with the microformats2 parsing specification: http://microformats.org/wiki/microformats2-parsing
14 stars 6 forks source link

Clarify parsing for mf2 property + mf2 root inside mf1 root #37

Open gRegorLove opened 6 years ago

gRegorLove commented 6 years ago

If there is a nested mf2 property + mf2 root inside an mf1 root, should parsers:

  1. Parse only the child mf2 root, in children
  2. Ignore both
  3. Parse the mf2 property as if it were inside an mf2 root

Example markup derived from @chrisaldrich's post, which temporarily lost the h-entry leaving hentry with mf2 u-invitee h-card properties:

<article class="hentry">
  <a href="https://example.com" class="u-invitee h-card">John Doe</a>
  <a href="https://gregorlove.com" class="u-invitee">gRegor</a>
</article>

The second link there, sans h-card, is to contrast that mf2 properties on their own inside an mf1 root are ignored.

php-mf2 result:

"items": [
    {
        "type": [
            "h-entry"
        ],
        "properties": {
            "invitee": [
                {
                    "type": [
                        "h-card"
                    ],
                    "properties": {
                        "name": [
                            "John Doe"
                        ],
                        "url": [
                            "https://example.com"
                        ]
                    },
                    "value": "https://example.com"
                }
            ]
        }
    }
]

mf2py result:

"items": [
    {
        "type": [
            "h-entry"
        ], 
        "properties": {}, 
        "children": [
            {
                "type": [
                    "h-card"
                ], 
                "properties": {
                    "url": [
                        "https://example.com"
                    ], 
                    "name": [
                        "John Doe"
                    ]
                }
            }
        ]
    }
]

microformats-node result:

"items": [{
    "type": ["h-entry"],
    "properties": {
        "invitee": [{
            "value": "https://example.com",
            "type": ["h-card"],
            "properties": {
                "name": ["John Doe"],
                "url": ["https://example.com"]
            }
        }]
    }
}]

I'm inclined to answer 1, like mf2py does.

The quote from http://microformats.org/wiki/microformats2-parsing that seems unclear is:

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:

"and is a property element" could be clarified so it's explicit about what to do in backcompat.

kartikprabhu commented 6 years ago

this is already clarified in the lines

if parsing a backcompat root, parse child element class name(s) for backcompat properties else parse a child element class for property class name(s) "p-,u-,dt-,e-"

gRegorLove commented 5 years ago

I understand the logic of it now, but I needed to re-read it a couple times. I wasn't holding that definition of "property" in mind when I got to the recursion step, instead I'd switched back to microformat properties in general.

I don't think this has caused confusion before, so maybe it's just me. A minimal formatting update to highlight it as a term might help:

  • if such class(es) are found, it is a property element
    • add properties found to current microformat's properties: { } structure
  • 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: