microformats2 parsing brainstorming

(Difference between revisions)

Jump to: navigation, search
(suggetsed enhanced rel parsing to preserve attributes)
(rel-tag: alternative output idea)
Line 32: Line 32:
     }]
     }]
   },  
   },  
 +
"items": []
 +
}
 +
</pre></code>
 +
 +
Alternative is to add a <code>urls</code> element to the parsed output with this extra data that can be looked up from the rels, which doesn't break backward compatibility and works better with xfn (see blow)
 +
 +
<code><pre>
 +
{
 +
"rels": {"tag": ["http://del.icio.us/tag/tech"]},
 +
"urls":
 +
  [
 +
  {"http://del.icio.us/tag/tech":
 +
    {
 +
    "name":"Technology",
 +
    "attrs":{},
 +
    "rels":["tag"],
 +
    }
 +
  }
 +
  ],
"items": []
"items": []
}  
}  

Revision as of 20:56, 22 April 2015


This page is for brainstorming, discussion, and other questions and explorations about microformats2 parsing.

For the microformats2 parsing algorithm, see:

Contents

more information for rel-based formats

Raised 2015-04-18 by Kevin Marks

Several rel-based formats have additional information that is useful beyond the link itself, which is all we capture at the moment. As I am trying to update the Universal feedparser to support mf2 based I will show examples from the testcases there.

rel-tag

<a rel="tag" href="http://del.icio.us/tag/tech">Technology</a> 

currently parses to:

{"rels": {"tag": ["http://del.icio.us/tag/tech"]}, "items": []} 

This loses the link text, which is useful as a label. Suggested output:

{
"rels": 
  {
  "tag": [{
    "url":"http://del.icio.us/tag/tech",
    "name":"Technology",
    "attrs":{}
    }]
  }, 
"items": []
} 

Alternative is to add a urls element to the parsed output with this extra data that can be looked up from the rels, which doesn't break backward compatibility and works better with xfn (see blow)

{
"rels": {"tag": ["http://del.icio.us/tag/tech"]}, 
"urls": 
  [
  {"http://del.icio.us/tag/tech":
    {
    "name":"Technology",
    "attrs":{},
    "rels":["tag"],
    }
  }
  ], 
"items": []
} 

xfn

<a rel="coworker" href="http://example.com/johndoe">John Doe</a>

currently parses to:

{"rels": {"coworker": ["http://example.com/johndoe"]}, "items": []}

This loses the link text, which is the person's name. Suggested output:

{
"rels": 
  {
  "coworker": [{
    "url":"http://example.com/johndoe",
    "name":"John Doe",
    "attrs":{}
    }]
  }, 
"items": []
} 

rel-enclosure

<a rel="enclosure" href="http://example.com/movie.mp4" type="video/mpeg" title="real title">my movie</a>

currently parses to:

'{"rels": {"enclosure": ["http://example.com/movie.mp4"]}, "items": []}'

This loses the link text, which is the title and the attributes which give type. Suggested output:

{
"rels":
  {
  "enclosure":[{
    "url":"http://example.com/movie.mp4",
    "name":"my movie",
    "attrs":{
      "type":"video/mpeg",
      "title":"real title"}
    }]
  },
  "items": []
} 

I think this generalises to other rel's too, such as rel-feed and rel-alternate that have type, lang etc attributes.

Nested h-* objects' "value" property

Raised 2015-01-06 by User:Kylewm;

If a child element has a microformat (h-*) and is a property element (p-*, u-*, dt-*, e-*), the parser will add a "value" property to the resulting object. The value should attempt to be a useful representation of the object for consumers that do not have semantic knowledge of the particular h-* type. Ref: microformats2-parsing#parse_an_element_for_class_microformats.

To determine the "value", we parse the property element simply (as if it did not have a h-* class), which works well for simple h-* objects, e.g. <a class="u-like-of h-cite" href="...">...</a>

  • To handle more complex microformats, I propose that "value" for a p-* property element take on the first explicit "name" property of the nested microformat, and for a u-* property, the first explicit "url" property. Parsing will fall back on the current rules if an explicit property does not exist.
    • This makes sense to me, and fits with the use-cases and examples I've seen. Tantek 19:31, 6 January 2015 (UTC)
    • A similar (possibly simpler?) formulation would use the implied name and url rules to determine the "value" for p-* and u-* properties respectively
      • I don't think that's needed, as there are already implied rules on a property that should handle that. I'd start with just the "first explicit" scoping to be more conservative, and then see if we find any use-cases that (and existing implied rules) don't/doesn't catch. Tantek 19:31, 6 January 2015 (UTC)

For example:

<div class="h-entry">
  <div class="u-in-reply-to h-cite">
    <a class="p-author h-card" href="http://example.com">Example Author</a>
    <a class="p-name u-url" href="http://example.com/post">Example Post</a>
  </div>
</div>

The nested u-in-reply-to object would parse as

...
"in-reply-to": [{ 
  "type": ["h-cite"],
  "properties": {
    "name": ["Example Post"],
    "url": ["http://example.com/post"],
    "author": [{
      "type":["h-card"],
      "properties": {
        "url": ["http://example.com"], 
        "name": ["Example Author"],
        "value": "Example Author"
      }
    }],
  },
  "value": "http://example.com/post"
}]
...

where the outer "value" gets the in-reply-to h-cite's u-url property, and the inner "value" gets the author's p-name property.

  • Because there are no implied properties of the dt-* and e-* types, and no obvious defaults, the value rules for these types would not change.
    • A possibility for dt-* h-*: The dt-* could take either the first dt-* of the h-*, or (perhaps if no dt-* in the h-*,) the first <time> element inside. Tantek 19:31, 6 January 2015 (UTC)
    • First dt-* seems reasonable, predictable, and usable. Consensus at 2015-01-20 meetup.

Canonicalization of datetime output

It would be useful to choose a (more) uniform output format for datetimes to make it easier for users of the parser to consume datetimes. Microformats2 parsers already do sophisticated pattern matching to recognize date vs. time vs. datetimes, so converting this to any specific format should not add overhead.

Specifically:

  • Choose either 'T' or space as the date/time separator.
    • Prefer space as it is more human friendly/readable, which matters even for syntaxes/formats, as human still develop, debug them. Tantek 19:31, 6 January 2015 (UTC)
  • Choose either +XXYY or +XX:YY as the timezone specification (and convert 'Z' to +0000).
    • Would appreciate some study / input here as to which timezone offset syntax is more human friendly. I lean slightly toward +/-NNNN (without the colon) because in the context of seeing a time, leaving out the colon makes it less likely the offset will be confused for a time. E.g. "07:00-08:00" looks like 7-8am, even if it meant 07:00 in PST. Tantek 19:31, 6 January 2015 (UTC)
    • Space is fine - consensus 2015-01-20 meetup.
  • Parsers should not attempt make datetimes more exact than specified. They should not add time, seconds, or timezone if omitted in the original. Kylewm 04:02, 14 May 2014 (UTC)
    • Agreed. Tantek 19:31, 6 January 2015 (UTC)
    • or month, day per Tom Morris
    • consensus 2015-01-20 meetup
  • Counterpoint: PHP's builtin date parsing does not require strict formatting. And the equivalent functionality for Python is provided by the widely used python-dateutil library. Kylewm 19:02, 14 May 2014 (UTC)
    • However we cannot (must not) depend on either PHP or Python's "smart" "fixing" or Postelian "liberal handling", or any other language/framework's for that matter, as they all differ in how "intelligent" they are. Tantek 19:31, 6 January 2015 (UTC)

Perhaps just provide a guideline for these based on the above consensus.

Add meta http-equiv to microformats2 parsing model

Similar to document level parsing of rel attributes, it makes sense simultaneously to parse <meta http-equiv> elements, perhaps treating "Status" in a special way (only using first number (sequence of digits) for its "value").

Use case: IndieWeb "deleted" indication inline in content for static file services that don't support HTTP return codes.

HTTP Header example:

HTML equivalent:

Related:

  • Interesting thought. Are you suggesting a top level "http-equivs:" collection similar to "rels:" in the parsed output? Should we consider "metas:" instead or in addition? Tantek 19:31, 6 January 2015 (UTC)

E.g. from https://gist.github.com/aaronpk/10297489

<meta http-equiv="Status" content="410 GONE"/>
{
 "items": [],
 "rels": {},
 "http": {
 "status": 410
 }
}
  • Maybe make this an optional pass in the parser? - Tom Morris 2015-01-20
  • For now, don't bother with metas until someone provides a use-case. Tom Morris
  • Agreed on both counts. Tantek 06:56, 21 January 2015 (UTC)



Other Interpretation Parsing Notes

Note: most of these need to be written up as separate microformats2-parsing-issues

Author: Ben Ward

Microformats 2 proposes a new, all encompassing syntax modification of prefixes that will allow microformats to be parsed from pages by processors without prior knowledge of a vocabulary. The core components of this model are quite simple, are quite simple to implement, but there are a number of conflicts that emerge with the functionality of existing microformats parsers that need to be handled. This page documents a proposed model to separate these concerns clearly in a way that can be applied to the documentation of generic microformats parsing rules, and the documentation of individual vocabularies.

Collection of other unresolved parsing issues in a generic model:

This is good material for documenting as microformats-2-issues, microformats-2-faq, and perhaps some of the more technical details in microformats-2-parsing-faq.

see also

microformats2 parsing brainstorming was last modified: Wednesday, December 31st, 1969

Views