Eureka Wiki (易易维基)

本页面的其他翻译:

您的足迹: microformats2

Microformats2

microformats2

欢迎来到microformats2主页。

摘要

Microformats2是微格式microformats的最新版,它是在HTML中标记结构化信息的最简单方法。Microformats2提高了作者(发布者)和开发者(解析器实现)两者的易用性和可实现性。.

Microformats2 取代了经典的微格式microformats (有时也叫做 microformats1),并给合了从microdataRDFa中学到的经验教训。

简单的 microformats2 例子

这里有一些简单的microformats2的例子,以及规范的 JSON.

人的例子

  • 简单的人的参考:
<span class="h-card">Frances Berriman</font>

解析为JSON:

{
  "items": [{ 
    "type": [["h-card"]],
    "properties": {
      "name": [["Frances|Berriman"]] 
    }
  }]
}

超链接的人

  • 简单超链接的人参考
<a class="h-card" href="http:<nowiki>//</nowiki>benward.me">Ben Ward</a>

解析为 JSON:

{
  "items": [{ 
    "type": [["h-card"]],
    "properties": {
      "name": [["Ben|Ward"]],
      "url": [["http://benward.me"]]
    }
  }]
}

超链接人图像

  • 简单超连接人图像
<a class="h-card" href="http:<nowiki>//</nowiki>rohit.khare.org/">
 <img alt="Rohit Khare"
      src="https://s3.amazonaws.com/twitter_production/profile_images/53307499/180px-Rohit-sq_bigger.jpg" />
</a>

解析为 JSON:

{
  "items": [{ 
    "type": [["h-card"]],
    "properties": {
      "name": [["Rohit|Khare"]],
      "url": [["http://rohit.khare.org/"]],
      "photo": [["https://s3.amazonaws.com/twitter_production/profile_images/53307499/180px-Rohit-sq_bigger.jpg"]]
    }
  }]
}

更多简单案例详情在 microformats-2-implied-properties.


详细个人信息例子

  • 更详细的个人信息
<div class="h-card">
  <img class="u-photo" alt="photo of Mitchell"
       src="https://webfwd.org/content/about-experts/300.mitchellbaker/mentor_mbaker.jpg"/>
  <a class="p-name u-url"
     href="http://blog.lizardwrangler.com/" 
    >Mitchell Baker</a>
 (<a class="u-url" 
     href="https://twitter.com/MitchellBaker"
    >@MitchellBaker</a>)
  <span class="p-org">Mozilla Foundation</font>
  <p class="p-note">
    Mitchell is responsible for setting the direction and scope of the Mozilla Foundation and its activities.
  </p>
  <span class="p-category">Strategy</font>
  <span class="p-category">Leadership</font>
</div>

解析为 JSON:

{
  "items": [{ 
    "type": [["h-card"]],
    "properties": {
      "photo": [["https://webfwd.org/content/about-experts/300.mitchellbaker/mentor_mbaker.jpg"]],
      "name": [["Mitchell|Baker"]],
      "url": [
        "http://blog.lizardwrangler.com/",
        "https://twitter.com/MitchellBaker"
      ],
      "org": [["Mozilla|Foundation"]],
      "note": [["Mitchell|is responsible for setting the direction and scope of the Mozilla Foundation and its activities."]],
      "category": [
        "Strategy",
        "Leadership"
      ]
    }
  }]
}

例子的细节

例子展示的细节:

  1. JSON “type” 使用完整的微格式根类名 (例如 “h-card”) 作为一致的标识。
  2. 所有属性都是可选的,并且在语法上是复数,并且具有文档顺序提供的解析值; 特定的微格式(及其应用)可能会将特定/单数语义应用于属性的第一个值。

microformats2 设计

microformats2 具有以下关键设计:

类名前缀

所有微格式类名都使用前缀。前缀是分开开发的 独立于词汇的语法, which are developed separately.

* h-* 作为根类名 (e.g. h-card)

  • p-* 作为纯文本属性 (e.g. p-name)
  • u-* 作为URL属性 (e.g. u-photo)
  • dt-* 作为日期/时间属性 (e.g. dt-bday)
  • e-* 作为嵌入标签属性 (e.g. e-note)

详情参见 microformats2-prefixes

可选属性一般集合

所有微格式都由一个根和一组属性组成。 分层数据用嵌套的微格式表示,通常作为属性值本身。 属性都是可选的并且可能是多值的(需要单一语义的应用可以使用第一实例)。

通用的单个类标记

常见的简单标记模式只需要一个微格式根类名称,解析器用它来查找几个通用属性:名称,网址,照片。 上面的简单的microformats2示例演示了这些。

更多内容参见microformat2