This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdfa.js
62 lines (60 loc) · 2.62 KB
/
rdfa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Module core/rdfa
// Support for RDFa is spread to multiple places in the code, including templates, as needed by
// the HTML being generated in various places. This is for parts that don't fit anywhere in
// particular
define(
[],
function () {
return {
run: function (conf, doc, cb, msg) {
msg.pub("start", "core/rdfa");
if (conf.doRDFa) {
$("section,nav").each(function () {
var $sec = $(this)
, resource = ""
, $fc = $sec.children("h1,h2,h3,h4,h5,h6").first()
, ref = $sec.attr("id")
, fcref = null
;
if (ref) {
resource = "#" + ref;
}
else if ($fc.length) {
ref = $fc.attr("id");
if (ref) {
resource = "#" + ref;
fcref = ref;
}
}
var property = "bibo:hasPart";
// Headings on everything but boilerplate
if (!resource.match(/#(abstract|sotd|toc)$/)) {
$sec.attr({
"typeof": "bibo:Chapter"
, resource: resource
, property: property
});
}
// create a heading triple too, as per the role spec
// since we should not be putting an @role on
// h* elements with a value of heading, but we
// still want the semantic markup
if ($fc.length) {
if (!fcref) {
// if there is no ID on the heading itself. Add one
fcref = $fc.makeID("h", ref) ;
}
// set the subject to the ID of the heading
$fc.attr({ resource: "#" + fcref }) ;
// nest the contents in a span so we can set the predicate
// and object
$fc.wrapInner( "<span property='xhv:role' resource='xhv:heading'></span>" );
}
});
}
msg.pub("end", "core/rdfa");
cb();
}
};
}
);