@lblod/graph-rdfa-processor 2.1.3 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- package/bug4.html +2212 -0
- package/bug5.html +952 -0
- package/dist/rdfa-graph.js +1 -1
- package/dist/rdfa-processor.js +4 -0
- package/package.json +1 -1
- package/src/rdfa-graph.js +10 -11
- package/src/rdfa-processor.js +25 -22
- package/test/test.js +5 -5
package/dist/rdfa-graph.js
CHANGED
@@ -556,7 +556,7 @@ function () {
|
|
556
556
|
var l = this.objects[i].value.toString();
|
557
557
|
|
558
558
|
if (l.indexOf("\n") >= 0 || l.indexOf("\r") >= 0) {
|
559
|
-
s += '"""' + l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"
|
559
|
+
s += '"""' + l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"/g, '\\"') + '"""';
|
560
560
|
} else {
|
561
561
|
s += '"' + l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"/g, '\\"') + '"';
|
562
562
|
}
|
package/dist/rdfa-processor.js
CHANGED
package/package.json
CHANGED
package/src/rdfa-graph.js
CHANGED
@@ -4,10 +4,10 @@ export class RDFaGraph {
|
|
4
4
|
constructor() {
|
5
5
|
var dataContext = this;
|
6
6
|
this.curieParser = {
|
7
|
-
trim: function
|
7
|
+
trim: function(str) {
|
8
8
|
return str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
|
9
9
|
},
|
10
|
-
parse: function
|
10
|
+
parse: function(value, resolve) {
|
11
11
|
value = this.trim(value);
|
12
12
|
if (value.charAt(0) == "[" && value.charAt(value.length - 1) == "]") {
|
13
13
|
value = value.substring(1, value.length - 1);
|
@@ -34,19 +34,19 @@ export class RDFaGraph {
|
|
34
34
|
},
|
35
35
|
};
|
36
36
|
this.base = null;
|
37
|
-
this.toString = function
|
37
|
+
this.toString = function(requestOptions) {
|
38
38
|
var options =
|
39
39
|
requestOptions && requestOptions.shorten
|
40
40
|
? { graph: this, shorten: true, prefixesUsed: {} }
|
41
41
|
: null;
|
42
42
|
if (requestOptions && requestOptions.blankNodePrefix) {
|
43
|
-
options.filterBlankNode = function
|
43
|
+
options.filterBlankNode = function(id) {
|
44
44
|
return "_:" + requestOptions.blankNodePrefix + id.substring(2);
|
45
45
|
};
|
46
46
|
}
|
47
47
|
if (requestOptions && requestOptions.numericalBlankNodePrefix) {
|
48
48
|
var onlyNumbers = /^[0-9]+$/;
|
49
|
-
options.filterBlankNode = function
|
49
|
+
options.filterBlankNode = function(id) {
|
50
50
|
var label = id.substring(2);
|
51
51
|
return onlyNumbers.test(label)
|
52
52
|
? "_:" + requestOptions.numericalBlankNodePrefix + label
|
@@ -72,7 +72,7 @@ export class RDFaGraph {
|
|
72
72
|
return prolog.length == 0 ? s : prolog + "\n" + s;
|
73
73
|
};
|
74
74
|
this.blankNodeCounter = 0;
|
75
|
-
this.clear = function
|
75
|
+
this.clear = function() {
|
76
76
|
this.subjects = {};
|
77
77
|
this.prefixes = {};
|
78
78
|
this.terms = {};
|
@@ -130,7 +130,7 @@ export class RDFaGraph {
|
|
130
130
|
Object.defineProperty(this, "tripleCount", {
|
131
131
|
enumerable: true,
|
132
132
|
configurable: false,
|
133
|
-
get: function
|
133
|
+
get: function() {
|
134
134
|
var count = 0;
|
135
135
|
for (var s in this.subjects) {
|
136
136
|
var snode = this.subjects[s];
|
@@ -480,12 +480,11 @@ export class RDFaPredicate {
|
|
480
480
|
}
|
481
481
|
} else {
|
482
482
|
var l = this.objects[i].value.toString();
|
483
|
+
|
483
484
|
if (l.indexOf("\n") >= 0 || l.indexOf("\r") >= 0) {
|
484
485
|
s +=
|
485
486
|
'"""' +
|
486
|
-
l
|
487
|
-
.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\")
|
488
|
-
.replace(/"""/g, '\\"\\"\\"') +
|
487
|
+
l.replace(/([^\\]|^)(\\)(?!\\)/g, "$1\\\\").replace(/"/g, '\\"') +
|
489
488
|
'"""';
|
490
489
|
} else {
|
491
490
|
s +=
|
@@ -507,7 +506,7 @@ export class RDFaPredicate {
|
|
507
506
|
}
|
508
507
|
}
|
509
508
|
|
510
|
-
RDFaPredicate.getPrefixMap = function
|
509
|
+
RDFaPredicate.getPrefixMap = function(e) {
|
511
510
|
var prefixMap = {};
|
512
511
|
while (e.attributes) {
|
513
512
|
for (var i = 0; i < e.attributes.length; i++) {
|
package/src/rdfa-processor.js
CHANGED
@@ -208,9 +208,9 @@ export default class RDFaProcessor extends URIResolver {
|
|
208
208
|
if (node.ownerDocument.doctype) {
|
209
209
|
if (
|
210
210
|
node.ownerDocument.doctype.publicId ==
|
211
|
-
|
211
|
+
"-//W3C//DTD XHTML+RDFa 1.0//EN" &&
|
212
212
|
node.ownerDocument.doctype.systemId ==
|
213
|
-
|
213
|
+
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"
|
214
214
|
) {
|
215
215
|
console.log(
|
216
216
|
"WARNING: RDF 1.0 is not supported. Defaulting to HTML5 mode.",
|
@@ -218,9 +218,9 @@ export default class RDFaProcessor extends URIResolver {
|
|
218
218
|
this.setHTMLContext();
|
219
219
|
} else if (
|
220
220
|
node.ownerDocument.doctype.publicId ==
|
221
|
-
|
221
|
+
"-//W3C//DTD XHTML+RDFa 1.1//EN" &&
|
222
222
|
node.ownerDocument.doctype.systemId ==
|
223
|
-
|
223
|
+
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"
|
224
224
|
) {
|
225
225
|
this.setXHTMLContext();
|
226
226
|
} else {
|
@@ -329,11 +329,11 @@ export default class RDFaProcessor extends URIResolver {
|
|
329
329
|
"http://www.w3.org/1999/xhtml/vocab#transformation";
|
330
330
|
}
|
331
331
|
|
332
|
-
init() {}
|
332
|
+
init() { }
|
333
333
|
|
334
|
-
newSubjectOrigin(origin, subject) {}
|
334
|
+
newSubjectOrigin(origin, subject) { }
|
335
335
|
|
336
|
-
addTriple(origin, subject, predicate, object) {}
|
336
|
+
addTriple(origin, subject, predicate, object) { }
|
337
337
|
|
338
338
|
process(node, options) {
|
339
339
|
if (node.nodeType == Node.DOCUMENT_NODE) {
|
@@ -344,7 +344,7 @@ export default class RDFaProcessor extends URIResolver {
|
|
344
344
|
}
|
345
345
|
var queue = [];
|
346
346
|
// Fix for Firefox that includes the hash in the base URI
|
347
|
-
var removeHash = function
|
347
|
+
var removeHash = function(baseURI) {
|
348
348
|
var hash = baseURI.indexOf("#");
|
349
349
|
if (hash >= 0) {
|
350
350
|
baseURI = baseURI.substring(0, hash);
|
@@ -352,6 +352,9 @@ export default class RDFaProcessor extends URIResolver {
|
|
352
352
|
if (options && options.baseURIMap) {
|
353
353
|
baseURI = options.baseURIMap(baseURI);
|
354
354
|
}
|
355
|
+
if (baseURI == "about:blank") {
|
356
|
+
baseURI = options.baseURI;
|
357
|
+
}
|
355
358
|
return baseURI;
|
356
359
|
};
|
357
360
|
queue.push({
|
@@ -864,18 +867,18 @@ export default class RDFaProcessor extends URIResolver {
|
|
864
867
|
datatypeAtt.value == ""
|
865
868
|
? RDFaProcessor.PlainLiteralURI
|
866
869
|
: this.parseTermOrCURIEOrAbsURI(
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
870
|
+
datatypeAtt.value,
|
871
|
+
vocabulary,
|
872
|
+
context.terms,
|
873
|
+
prefixes,
|
874
|
+
base,
|
875
|
+
);
|
873
876
|
if (datetimeAtt && !contentAtt) {
|
874
877
|
content = datetimeAtt.value;
|
875
878
|
} else {
|
876
879
|
content =
|
877
880
|
datatype == RDFaProcessor.XMLLiteralURI ||
|
878
|
-
|
881
|
+
datatype == RDFaProcessor.HTMLLiteralURI
|
879
882
|
? null
|
880
883
|
: contentAtt
|
881
884
|
? contentAtt.value
|
@@ -943,10 +946,10 @@ export default class RDFaProcessor extends URIResolver {
|
|
943
946
|
datatype == RDFaProcessor.HTMLLiteralURI
|
944
947
|
? { type: datatype, value: current.childNodes }
|
945
948
|
: {
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
949
|
+
type: datatype ? datatype : RDFaProcessor.PlainLiteralURI,
|
950
|
+
value: content,
|
951
|
+
language: language,
|
952
|
+
},
|
950
953
|
);
|
951
954
|
} else {
|
952
955
|
if (
|
@@ -1073,7 +1076,7 @@ export default class RDFaProcessor extends URIResolver {
|
|
1073
1076
|
}
|
1074
1077
|
}
|
1075
1078
|
|
1076
|
-
copyProperties() {}
|
1079
|
+
copyProperties() { }
|
1077
1080
|
|
1078
1081
|
push(parent, subject) {
|
1079
1082
|
return {
|
@@ -1108,7 +1111,7 @@ RDFaProcessor.NCNAME = new RegExp(
|
|
1108
1111
|
"^" + RDFaProcessor.nameStartChar + RDFaProcessor.nameChar + "*$",
|
1109
1112
|
);
|
1110
1113
|
|
1111
|
-
RDFaProcessor.trim = function
|
1114
|
+
RDFaProcessor.trim = function(str) {
|
1112
1115
|
return str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
|
1113
1116
|
};
|
1114
1117
|
|
@@ -1144,7 +1147,7 @@ RDFaProcessor.dateTimeTypes = [
|
|
1144
1147
|
},
|
1145
1148
|
];
|
1146
1149
|
|
1147
|
-
RDFaProcessor.deriveDateTimeType = function
|
1150
|
+
RDFaProcessor.deriveDateTimeType = function(value) {
|
1148
1151
|
for (var i = 0; i < RDFaProcessor.dateTimeTypes.length; i++) {
|
1149
1152
|
//console.log("Checking "+value+" against "+RDFaProcessor.dateTimeTypes[i].type);
|
1150
1153
|
var matched = RDFaProcessor.dateTimeTypes[i].pattern.exec(value);
|
package/test/test.js
CHANGED
@@ -2,7 +2,7 @@ import { jsdom } from "jsdom";
|
|
2
2
|
import assert from "assert";
|
3
3
|
import getRDFaGraph from "../src";
|
4
4
|
import { readFileSync, writeFileSync } from "fs";
|
5
|
-
describe("getRDFaGraph", function
|
5
|
+
describe("getRDFaGraph", function() {
|
6
6
|
let html = `<div typeof="rdfs:Class" resource="http://schema.org/CreativeWork">
|
7
7
|
<span class="h" property="rdfs:label">CreativeWork</span>
|
8
8
|
<span property="rdfs:comment">The most generic kind of creative work, including books, movies, photographs, software programs, etc.</span>
|
@@ -17,14 +17,14 @@ describe("getRDFaGraph", function () {
|
|
17
17
|
<http://purl.org/dc/terms/source> <http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews> .
|
18
18
|
`;
|
19
19
|
|
20
|
-
it("should getRDFaGraph from a document", function
|
20
|
+
it("should getRDFaGraph from a document", function() {
|
21
21
|
let { document } = jsdom(html).defaultView.window;
|
22
22
|
let graph = getRDFaGraph(document, { baseURI: "http://localhost" });
|
23
23
|
assert.equal(graph.toString(), expected);
|
24
24
|
});
|
25
25
|
|
26
|
-
it
|
27
|
-
let ht = readFileSync("./
|
26
|
+
it("whatever", () => {
|
27
|
+
let ht = readFileSync("./bug4.html");
|
28
28
|
let { document } = jsdom(ht).defaultView.window;
|
29
29
|
|
30
30
|
let graph = getRDFaGraph(document, {
|
@@ -40,7 +40,7 @@ describe("getRDFaGraph", function () {
|
|
40
40
|
writeFileSync("/tmp/x.ttl", graph.toString(), "utf8");
|
41
41
|
});
|
42
42
|
|
43
|
-
it("should getRDFaGraph from a node", function
|
43
|
+
it("should getRDFaGraph from a node", function() {
|
44
44
|
let { document } = jsdom(html).defaultView.window;
|
45
45
|
let graph = getRDFaGraph(document.getElementsByTagName("div")[0], {
|
46
46
|
baseURI: "http://localhost",
|