如何使用RDFa编写/格式化HTML以便在源代码中易于人工阅读?

时间:2012-11-05 23:33:10

标签: html5 readability code-readability rdfa human-readable

添加RDFa非常有趣,但往往使我的源几乎无法读取,(即使编辑器具有良好的语法高亮功能。)例如:

<div id="me" prefix="foaf: http://xmlns.com/foaf/0.1/ schema:
http://schema.org/Person" typeof="foaf:Person schema:Person"
resource="http://carlboettiger.info#me"> <p> <img property="foaf:depiction"
src="assets/img/carlboettiger.png" alt="Photo of Carl Boettiger"
style="float: right; margin: 10px 10px"/>
I am  <a property="foaf:homepage schema:url"
href="http://carlboettiger.info"><span property="foaf:name
schema:name"><span property="foaf:givenName schema:givenName">Carl</span>
<span property="foaf:familyName schema:familyName">Boettiger</span></span></a>, <span
property="schema:jobTitle">a graduate student</span> with <span property="foaf:knows"><span
typeof="foaf:Person"><span property="foaf:name"><a property="foaf:homepage"
href="http://two.ucdavis.edu/%7Eme">Alan Hastings</a>
</span></span></span> in the <a property="foaf:workplaceHomepage"
href="http://www-eve.ucdavis.edu/eve/pbg/">Population Biology</a>
Ph.D program at<span property="schema:affiliation">UC Davis</span>,
working on <span property="foaf:interest">regime shifts</span>
in <span property="foaf:interest">ecology</span> and <span
property="foaf:interest">evolution</span>. Such shifts mark the most
dramatic events in <span property="foaf:interest">complex systems</span>

我一般不喜欢密集标记,因此我经常更喜欢用markdown编写,但在添加RDFa标记的上下文中这似乎是不可能的,例如本例。

似乎有人可能会利用空格来使这个更具人性化。是否有任何现有的工具或惯例? (以下示例仅来自vim中的!fmt wordwrapping,这通常看起来不错,但在这种情况下似乎不知所措。

1 个答案:

答案 0 :(得分:3)

  • 你应该更喜欢使用广泛的本体而不是复制已经具有等价物的类或谓词(或者只生成owl:equivalentClass或owl:sameAs关系)
  • RDFa 1.1中有许多未使用的快捷方式,例如vocab或rel属性
  • 您可以使用缩进来标记标记

根据这一点,您的页面可能如下所示:

<body prefix="schema: http://schema.org/"
      vocab="http://xmlns.com/foaf/0.1/">
    <p typeof="Person" resource="http://carlboettiger.info#me">
    <img property="depiction" style="float: right; margin: 10px 10px"
         src="assets/img/carlboettiger.png" alt="Photo of Carl Boettiger" />
    I am <a property="homepage schema:url" href="http://carlboettiger.info">
        <span property="name"><span property="givenName">Carl</span> <span property="familyName">Boettiger</span></span>
    </a>, a <span property="schema:jobTitle">graduate student</span> with
    <span rel="knows" typeof="Person">
        <span property="name"><a property="homepage" href="http://two.ucdavis.edu/%7Eme">Alan Hastings</a></span>
    </span> in the <a property="workplaceHomepage" href="http://www-eve.ucdavis.edu/eve/pbg/">Population Biology</a>
    Ph.D program at <span property="schema:affiliation">UC Davis</span>, working on
    <span rel="interest">
        <a href="http://en.wikipedia.org/wiki/Regime_shifts">regime shifts</a> in
        <a href="http://en.wikipedia.org/wiki/Ecology">ecology</a> and
        <a href="http://en.wikipedia.org/wiki/Evolution">evolution</a>.
        Such shifts mark the most dramatic events in <span>complex systems</span>
    </span>
    </p>
</body>