graph-rdfa-processor
Advanced tools
| version: 2 | ||
| jobs: | ||
| test: | ||
| working_directory: ~/graph-rdfa-processor | ||
| docker: | ||
| - image: circleci/node:dubnium | ||
| steps: | ||
| - checkout | ||
| - run: echo '//registry.npmjs.org/:_authToken='$NPM_PRIVATE_AUTH_TOKEN > $HOME/.npmrc | ||
| - restore_cache: | ||
| keys: | ||
| - v1-node_modules-{{ checksum "package-lock.json" }} | ||
| - v1-node_modules- | ||
| - run: | ||
| command: npm install | ||
| no_output_timeout: 5m | ||
| - save_cache: | ||
| key: v1-node_modules-{{ checksum "package-lock.json" }} | ||
| paths: | ||
| - node_modules | ||
| - run: npm test | ||
| - persist_to_workspace: | ||
| root: ~/graph-rdfa-processor | ||
| paths: . | ||
| publish: | ||
| working_directory: ~/graph-rdfa-processor | ||
| docker: | ||
| - image: circleci/node:dubnium | ||
| steps: | ||
| - attach_workspace: | ||
| at: ~/graph-rdfa-processor | ||
| - run: | ||
| name: Authenticate with registry | ||
| command: echo '//registry.npmjs.org/:_authToken='$NPM_PRIVATE_AUTH_TOKEN > $HOME/.npmrc | ||
| - run: | ||
| name: Publish package | ||
| command: npm publish | ||
| workflows: | ||
| version: 2 | ||
| test-publish: | ||
| jobs: | ||
| - test: | ||
| filters: # required since `publish` has tag filters AND requires `test` | ||
| tags: | ||
| only: /.*/ | ||
| - publish: | ||
| requires: | ||
| - test | ||
| filters: | ||
| branches: | ||
| ignore: /.*/ | ||
| tags: | ||
| only: /^v.*/ |
@@ -1,2 +0,2 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
@@ -6,20 +6,31 @@ Object.defineProperty(exports, "__esModule", { | ||
| }); | ||
| exports.default = void 0; | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
| var _rdfaProcessor = _interopRequireDefault(require("./rdfa-processor")); | ||
| var _rdfaProcessor = require('./rdfa-processor'); | ||
| var _rdfaGraph = require("./rdfa-graph"); | ||
| var _rdfaProcessor2 = _interopRequireDefault(_rdfaProcessor); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| var _rdfaGraph = require('./rdfa-graph'); | ||
| function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
| function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
| function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
| function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
| var GraphRDFaProcessor = function (_RDFaProcessor) { | ||
| function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
| function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
| function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
| function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
| function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
| var GraphRDFaProcessor = | ||
| /*#__PURE__*/ | ||
| function (_RDFaProcessor) { | ||
| _inherits(GraphRDFaProcessor, _RDFaProcessor); | ||
@@ -30,9 +41,10 @@ | ||
| return _possibleConstructorReturn(this, (GraphRDFaProcessor.__proto__ || Object.getPrototypeOf(GraphRDFaProcessor)).call(this, target)); | ||
| return _possibleConstructorReturn(this, _getPrototypeOf(GraphRDFaProcessor).call(this, target)); | ||
| } | ||
| _createClass(GraphRDFaProcessor, [{ | ||
| key: 'getObjectSize', | ||
| key: "getObjectSize", | ||
| value: function getObjectSize(obj) { | ||
| var size = 0; | ||
| for (var key in obj) { | ||
@@ -43,6 +55,7 @@ if (obj.hasOwnProperty(key)) { | ||
| } | ||
| return size; | ||
| } | ||
| }, { | ||
| key: 'init', | ||
| key: "init", | ||
| value: function init() { | ||
@@ -53,2 +66,3 @@ var thisObj = this; | ||
| var snode = thisObj.target.graph.subjects[subject]; | ||
| if (thisObj.getObjectSize(snode.predicates) == 0) { | ||
@@ -61,3 +75,3 @@ delete thisObj.target.graph.subjects[subject]; | ||
| }, { | ||
| key: 'newBlankNode', | ||
| key: "newBlankNode", | ||
| value: function newBlankNode() { | ||
@@ -67,5 +81,6 @@ return this.target.graph.newBlankNode(); | ||
| }, { | ||
| key: 'newSubjectOrigin', | ||
| key: "newSubjectOrigin", | ||
| value: function newSubjectOrigin(origin, subject) { | ||
| var snode = this.newSubject(null, subject); | ||
| for (var i = 0; i < snode.origins.length; i++) { | ||
@@ -76,3 +91,5 @@ if (snode.origins[i] === origin) { | ||
| } | ||
| snode.origins.push(origin); | ||
| if (!origin.data) { | ||
@@ -88,5 +105,6 @@ Object.defineProperty(origin, "data", { | ||
| }, { | ||
| key: 'newSubject', | ||
| key: "newSubject", | ||
| value: function newSubject(origin, subject) { | ||
| var snode = this.target.graph.subjects[subject]; | ||
| if (!snode) { | ||
@@ -96,9 +114,11 @@ snode = new _rdfaGraph.RDFaSubject(this.target.graph, subject); | ||
| } | ||
| return snode; | ||
| } | ||
| }, { | ||
| key: 'addTriple', | ||
| key: "addTriple", | ||
| value: function addTriple(origin, subject, predicate, object) { | ||
| var snode = this.newSubject(origin, subject); | ||
| var pnode = snode.predicates[predicate]; | ||
| if (!pnode) { | ||
@@ -117,10 +137,14 @@ pnode = new _rdfaGraph.RDFaPredicate(predicate); | ||
| } | ||
| pnode.objects[i].origin.push(origin); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| pnode.objects.push(object); | ||
| object.origin = origin; | ||
| if (predicate == _rdfaProcessor2.default.typeURI) { | ||
| if (predicate == _rdfaProcessor.default.typeURI) { | ||
| snode.types.push(object.value); | ||
@@ -130,45 +154,61 @@ } | ||
| }, { | ||
| key: 'copyProperties', | ||
| key: "copyProperties", | ||
| value: function copyProperties() { | ||
| var copySubjects = []; | ||
| var patternSubjects = {}; | ||
| for (var subject in this.target.graph.subjects) { | ||
| var snode = this.target.graph.subjects[subject]; | ||
| var pnode = snode.predicates[GraphRDFaProcessor.rdfaCopyPredicate]; | ||
| if (!pnode) { | ||
| continue; | ||
| } | ||
| copySubjects.push(subject); | ||
| for (var i = 0; i < pnode.objects.length; i++) { | ||
| if (pnode.objects[i].type != _rdfaProcessor2.default.objectURI) { | ||
| if (pnode.objects[i].type != _rdfaProcessor.default.objectURI) { | ||
| continue; | ||
| } | ||
| var target = pnode.objects[i].value; | ||
| var patternSubjectNode = this.target.graph.subjects[target]; | ||
| if (!patternSubjectNode) { | ||
| continue; | ||
| } | ||
| var patternTypes = patternSubjectNode.predicates[_rdfaProcessor2.default.typeURI]; | ||
| var patternTypes = patternSubjectNode.predicates[_rdfaProcessor.default.typeURI]; | ||
| if (!patternTypes) { | ||
| continue; | ||
| } | ||
| var isPattern = false; | ||
| for (var j = 0; j < patternTypes.objects.length && !isPattern; j++) { | ||
| if (patternTypes.objects[j].value == GraphRDFaProcessor.rdfaPatternType && patternTypes.objects[j].type == _rdfaProcessor2.default.objectURI) { | ||
| if (patternTypes.objects[j].value == GraphRDFaProcessor.rdfaPatternType && patternTypes.objects[j].type == _rdfaProcessor.default.objectURI) { | ||
| isPattern = true; | ||
| } | ||
| } | ||
| if (!isPattern) { | ||
| continue; | ||
| } | ||
| patternSubjects[target] = true; | ||
| for (var predicate in patternSubjectNode.predicates) { | ||
| var targetPNode = patternSubjectNode.predicates[predicate]; | ||
| if (predicate == _rdfaProcessor2.default.typeURI) { | ||
| if (predicate == _rdfaProcessor.default.typeURI) { | ||
| if (targetPNode.objects.length == 1) { | ||
| continue; | ||
| } | ||
| for (var j = 0; j < targetPNode.objects.length; j++) { | ||
| if (targetPNode.objects[j].value != GraphRDFaProcessor.rdfaPatternType) { | ||
| var subjectPNode = snode.predicates[predicate]; | ||
| if (!subjectPNode) { | ||
@@ -178,6 +218,9 @@ subjectPNode = new _rdfaGraph.RDFaPredicate(predicate); | ||
| } | ||
| subjectPNode.objects.push({ type: targetPNode.objects[j].type, | ||
| subjectPNode.objects.push({ | ||
| type: targetPNode.objects[j].type, | ||
| value: targetPNode.objects[j].value, | ||
| language: targetPNode.objects[j].language, | ||
| origin: targetPNode.objects[j].origin }); | ||
| origin: targetPNode.objects[j].origin | ||
| }); | ||
| snode.types.push(targetPNode.objects[j].value); | ||
@@ -188,2 +231,3 @@ } | ||
| var subjectPNode = snode.predicates[predicate]; | ||
| if (!subjectPNode) { | ||
@@ -193,7 +237,10 @@ subjectPNode = new _rdfaGraph.RDFaPredicate(predicate); | ||
| } | ||
| for (var j = 0; j < targetPNode.objects.length; j++) { | ||
| subjectPNode.objects.push({ type: targetPNode.objects[j].type, | ||
| subjectPNode.objects.push({ | ||
| type: targetPNode.objects[j].type, | ||
| value: targetPNode.objects[j].value, | ||
| language: targetPNode.objects[j].language, | ||
| origin: targetPNode.objects[j].origin }); | ||
| origin: targetPNode.objects[j].origin | ||
| }); | ||
| } | ||
@@ -204,2 +251,3 @@ } | ||
| } | ||
| for (var i = 0; i < copySubjects.length; i++) { | ||
@@ -209,2 +257,3 @@ var snode = this.target.graph.subjects[copySubjects[i]]; | ||
| } | ||
| for (var subject in patternSubjects) { | ||
@@ -217,9 +266,8 @@ delete this.target.graph.subjects[subject]; | ||
| return GraphRDFaProcessor; | ||
| }(_rdfaProcessor2.default); | ||
| }(_rdfaProcessor.default); | ||
| exports.default = GraphRDFaProcessor; | ||
| ; | ||
| GraphRDFaProcessor.rdfaCopyPredicate = "http://www.w3.org/ns/rdfa#copy"; | ||
| GraphRDFaProcessor.rdfaPatternType = "http://www.w3.org/ns/rdfa#Pattern"; | ||
| module.exports = exports['default']; | ||
| module.exports = exports.default; |
+15
-22
@@ -1,2 +0,2 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
@@ -6,34 +6,27 @@ Object.defineProperty(exports, "__esModule", { | ||
| }); | ||
| exports.default = _default; | ||
| exports.default = function (document) { | ||
| var _uriResolver = _interopRequireDefault(require("./uri-resolver")); | ||
| var _graphRdfaProcessor = _interopRequireDefault(require("./graph-rdfa-processor")); | ||
| var _rdfaGraph = require("./rdfa-graph"); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _default(document) { | ||
| var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
| var node = document.documentElement || document; | ||
| var baseURI = options.baseURI ? options.baseURI : node.baseURI; | ||
| var graph = new _rdfaGraph.RDFaGraph(); | ||
| var target = { | ||
| graph: graph, | ||
| baseURI: new _uriResolver2.default().parseURI(baseURI) | ||
| baseURI: new _uriResolver.default().parseURI(baseURI) | ||
| }; | ||
| var processor = new _graphRdfaProcessor2.default(target); | ||
| var processor = new _graphRdfaProcessor.default(target); | ||
| processor.process(node, options); | ||
| return target.graph; | ||
| }; | ||
| } | ||
| var _uriResolver = require('./uri-resolver'); | ||
| var _uriResolver2 = _interopRequireDefault(_uriResolver); | ||
| var _graphRdfaProcessor = require('./graph-rdfa-processor'); | ||
| var _graphRdfaProcessor2 = _interopRequireDefault(_graphRdfaProcessor); | ||
| var _rdfaGraph = require('./rdfa-graph'); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| ; | ||
| module.exports = exports['default']; | ||
| module.exports = exports.default; |
+4
-3
@@ -6,2 +6,3 @@ "use strict"; | ||
| }); | ||
| exports.default = void 0; | ||
| var Node = { | ||
@@ -21,4 +22,4 @@ ELEMENT_NODE: 1, | ||
| }; | ||
| exports.default = Node; | ||
| module.exports = exports["default"]; | ||
| var _default = Node; | ||
| exports.default = _default; | ||
| module.exports = exports.default; |
+159
-46
@@ -1,2 +0,2 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
@@ -6,17 +6,19 @@ Object.defineProperty(exports, "__esModule", { | ||
| }); | ||
| exports.RDFaPredicate = exports.RDFaSubject = exports.RDFaGraph = undefined; | ||
| exports.RDFaPredicate = exports.RDFaSubject = exports.RDFaGraph = void 0; | ||
| var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
| var _node = _interopRequireDefault(require("./node")); | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| var _node = require('./node'); | ||
| function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| var _node2 = _interopRequireDefault(_node); | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
| var RDFaGraph = exports.RDFaGraph = function () { | ||
| var RDFaGraph = | ||
| /*#__PURE__*/ | ||
| function () { | ||
| function RDFaGraph() { | ||
@@ -32,8 +34,12 @@ _classCallCheck(this, RDFaGraph); | ||
| value = this.trim(value); | ||
| if (value.charAt(0) == '[' && value.charAt(value.length - 1) == ']') { | ||
| value = value.substring(1, value.length - 1); | ||
| } | ||
| var colon = value.indexOf(":"); | ||
| if (colon >= 0) { | ||
| var prefix = value.substring(0, colon); | ||
| if (prefix == "") { | ||
@@ -48,2 +54,3 @@ // default prefix | ||
| var uri = dataContext.prefixes[prefix]; | ||
| if (uri) { | ||
@@ -59,4 +66,10 @@ return uri + value.substring(colon + 1); | ||
| this.base = null; | ||
| this.toString = function (requestOptions) { | ||
| var options = requestOptions && requestOptions.shorten ? { graph: this, shorten: true, prefixesUsed: {} } : null; | ||
| var options = requestOptions && requestOptions.shorten ? { | ||
| graph: this, | ||
| shorten: true, | ||
| prefixesUsed: {} | ||
| } : null; | ||
| if (requestOptions && requestOptions.blankNodePrefix) { | ||
@@ -67,4 +80,6 @@ options.filterBlankNode = function (id) { | ||
| } | ||
| if (requestOptions && requestOptions.numericalBlankNodePrefix) { | ||
| var onlyNumbers = /^[0-9]+$/; | ||
| options.filterBlankNode = function (id) { | ||
@@ -75,3 +90,5 @@ var label = id.substring(2); | ||
| } | ||
| var s = ""; | ||
| for (var subject in this.subjects) { | ||
@@ -82,3 +99,5 @@ var snode = this.subjects[subject]; | ||
| } | ||
| var prolog = requestOptions && requestOptions.baseURI ? "@base <" + baseURI + "> .\n" : ""; | ||
| if (options && options.shorten) { | ||
@@ -89,5 +108,8 @@ for (var prefix in options.prefixesUsed) { | ||
| } | ||
| return prolog.length == 0 ? s : prolog + "\n" + s; | ||
| }; | ||
| this.blankNodeCounter = 0; | ||
| this.clear = function () { | ||
@@ -99,6 +121,6 @@ this.subjects = {}; | ||
| }; | ||
| this.clear(); | ||
| this.prefixes[""] = "http://www.w3.org/1999/xhtml/vocab#"; | ||
| this.prefixes[""] = "http://www.w3.org/1999/xhtml/vocab#"; // w3c | ||
| // w3c | ||
| this.prefixes["grddl"] = "http://www.w3.org/2003/g/data-view#"; | ||
@@ -118,4 +140,4 @@ this.prefixes["ma"] = "http://www.w3.org/ns/ma-ont#"; | ||
| this.prefixes["xml"] = "http://www.w3.org/XML/1998/namespace"; | ||
| this.prefixes["xsd"] = "http://www.w3.org/2001/XMLSchema#"; | ||
| // non-rec w3c | ||
| this.prefixes["xsd"] = "http://www.w3.org/2001/XMLSchema#"; // non-rec w3c | ||
| this.prefixes["sd"] = "http://www.w3.org/ns/sparql-service-description#"; | ||
@@ -128,4 +150,4 @@ this.prefixes["org"] = "http://www.w3.org/ns/org#"; | ||
| this.prefixes["ht"] = "http://www.w3.org/2006/http#"; | ||
| this.prefixes["ptr"] = "http://www.w3.org/2009/pointers#"; | ||
| // widely used | ||
| this.prefixes["ptr"] = "http://www.w3.org/2009/pointers#"; // widely used | ||
| this.prefixes["cc"] = "http://creativecommons.org/ns#"; | ||
@@ -143,9 +165,7 @@ this.prefixes["ctag"] = "http://commontag.org/ns#"; | ||
| this.prefixes["vcard"] = "http://www.w3.org/2006/vcard/ns#"; | ||
| this.prefixes["schema"] = "http://schema.org/"; | ||
| this.prefixes["schema"] = "http://schema.org/"; // terms | ||
| // terms | ||
| this.terms["describedby"] = "http://www.w3.org/2007/05/powder-s#describedby"; | ||
| this.terms["license"] = "http://www.w3.org/1999/xhtml/vocab#license"; | ||
| this.terms["role"] = "http://www.w3.org/1999/xhtml/vocab#role"; | ||
| Object.defineProperty(this, "tripleCount", { | ||
@@ -156,4 +176,6 @@ enumerable: true, | ||
| var count = 0; | ||
| for (var s in this.subjects) { | ||
| var snode = this.subjects[s]; | ||
| for (var p in snode.predicates) { | ||
@@ -163,2 +185,3 @@ count += snode.predicates[p].objects.length; | ||
| } | ||
| return count; | ||
@@ -170,3 +193,3 @@ } | ||
| _createClass(RDFaGraph, [{ | ||
| key: 'newBlankNode', | ||
| key: "newBlankNode", | ||
| value: function newBlankNode() { | ||
@@ -177,3 +200,3 @@ this.blankNodeCounter++; | ||
| }, { | ||
| key: 'expand', | ||
| key: "expand", | ||
| value: function expand(curie) { | ||
@@ -183,6 +206,7 @@ return this.curieParser.parse(curie, true); | ||
| }, { | ||
| key: 'shorten', | ||
| key: "shorten", | ||
| value: function shorten(uri, prefixesUsed) { | ||
| for (prefix in this.prefixes) { | ||
| var mapped = this.prefixes[prefix]; | ||
| if (uri.indexOf(mapped) == 0) { | ||
@@ -192,9 +216,11 @@ if (prefixesUsed) { | ||
| } | ||
| return prefix + ":" + uri.substring(mapped.length); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| }, { | ||
| key: 'add', | ||
| key: "add", | ||
| value: function add(subject, predicate, object, options) { | ||
@@ -204,5 +230,7 @@ if (!subject || !predicate || !object) { | ||
| } | ||
| subject = this.expand(subject); | ||
| predicate = this.expand(predicate); | ||
| var snode = this.subjects[subject]; | ||
| if (!snode) { | ||
@@ -212,9 +240,13 @@ snode = new RDFaSubject(this, subject); | ||
| } | ||
| if (options && options.origin) { | ||
| snode.origins.push(options.origin); | ||
| } | ||
| if (predicate == "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") { | ||
| snode.types.push(object); | ||
| } | ||
| var pnode = snode.predicates[predicate]; | ||
| if (!pnode) { | ||
@@ -240,3 +272,3 @@ pnode = new RDFaPredicate(predicate); | ||
| }, { | ||
| key: 'addCollection', | ||
| key: "addCollection", | ||
| value: function addCollection(subject, predicate, objectList, options) { | ||
@@ -249,18 +281,27 @@ if (!subject || !predicate || !objectList) { | ||
| var lastPredicate = predicate; | ||
| for (var i = 0; i < objectList.length; i++) { | ||
| var object = { type: options && options.type ? options.type : "rdf:PlainLiteral" }; | ||
| var object = { | ||
| type: options && options.type ? options.type : "rdf:PlainLiteral" | ||
| }; | ||
| if (options && options.language) { | ||
| object.language = options.language; | ||
| } | ||
| if (options && options.datatype) { | ||
| object.datatype = options.datatype; | ||
| } | ||
| if (_typeof(objectList[i]) == "object") { | ||
| object.value = objectList[i].value ? objectList[i].value : ""; | ||
| if (objectList[i].type) { | ||
| object.type = objectList[i].type; | ||
| } | ||
| if (objectList[i].language) { | ||
| object.language = objectList[i].language; | ||
| } | ||
| if (objectList[i].datatype) { | ||
@@ -272,4 +313,8 @@ object.datatype = objectList[i].datatype; | ||
| } | ||
| var bnode = this.newBlankNode(); | ||
| this.add(lastSubject, lastPredicate, { type: "rdf:object", value: bnode }); | ||
| this.add(lastSubject, lastPredicate, { | ||
| type: "rdf:object", | ||
| value: bnode | ||
| }); | ||
| this.add(bnode, "rdf:first", object); | ||
@@ -279,6 +324,10 @@ lastSubject = bnode; | ||
| } | ||
| this.add(lastSubject, lastPredicate, { type: "rdf:object", value: "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" }); | ||
| this.add(lastSubject, lastPredicate, { | ||
| type: "rdf:object", | ||
| value: "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" | ||
| }); | ||
| } | ||
| }, { | ||
| key: 'remove', | ||
| key: "remove", | ||
| value: function remove(subject, predicate) { | ||
@@ -289,7 +338,10 @@ if (!subject) { | ||
| } | ||
| subject = this.expand(subject); | ||
| var snode = this.subjects[snode]; | ||
| if (!snode) { | ||
| return; | ||
| } | ||
| if (!predicate) { | ||
@@ -299,2 +351,3 @@ delete this.subjects[subject]; | ||
| } | ||
| predicate = this.expand(predicate); | ||
@@ -308,10 +361,13 @@ delete snode.predicates[predicate]; | ||
| exports.RDFaGraph = RDFaGraph; | ||
| ; | ||
| var RDFaSubject = exports.RDFaSubject = function () { | ||
| var RDFaSubject = | ||
| /*#__PURE__*/ | ||
| function () { | ||
| function RDFaSubject(graph, subject) { | ||
| _classCallCheck(this, RDFaSubject); | ||
| this.graph = graph; | ||
| // TODO: subject or id? | ||
| this.graph = graph; // TODO: subject or id? | ||
| this.subject = subject; | ||
@@ -325,5 +381,6 @@ this.id = subject; | ||
| _createClass(RDFaSubject, [{ | ||
| key: 'toString', | ||
| key: "toString", | ||
| value: function toString(options) { | ||
| var s = null; | ||
| if (this.subject.substring(0, 2) == "_:") { | ||
@@ -337,2 +394,3 @@ if (options && options.filterBlankNode) { | ||
| s = this.graph.shorten(this.subject, options.prefixesUsed); | ||
| if (!s) { | ||
@@ -344,3 +402,5 @@ s = "<" + this.subject + ">"; | ||
| } | ||
| var first = true; | ||
| for (var predicate in this.predicates) { | ||
@@ -352,4 +412,6 @@ if (!first) { | ||
| } | ||
| s += " " + this.predicates[predicate].toString(options); | ||
| } | ||
| s += " ."; | ||
@@ -359,39 +421,65 @@ return s; | ||
| }, { | ||
| key: 'toObject', | ||
| key: "toObject", | ||
| value: function toObject() { | ||
| var o = { subject: this.subject, predicates: {} }; | ||
| var o = { | ||
| subject: this.subject, | ||
| predicates: {} | ||
| }; | ||
| for (var predicate in this.predicates) { | ||
| var pnode = this.predicates[predicate]; | ||
| var p = { predicate: predicate, objects: [] }; | ||
| var p = { | ||
| predicate: predicate, | ||
| objects: [] | ||
| }; | ||
| o.predicates[predicate] = p; | ||
| for (var i = 0; i < pnode.objects.length; i++) { | ||
| var object = pnode.objects[i]; | ||
| if (object.type == RDFaProcessor.XMLLiteralURI) { | ||
| var serializer = new XMLSerializer(); | ||
| var value = ""; | ||
| for (var x = 0; x < object.value.length; x++) { | ||
| if (object.value[x].nodeType == _node2.default.ELEMENT_NODE) { | ||
| if (object.value[x].nodeType == _node.default.ELEMENT_NODE) { | ||
| value += serializer.serializeToString(object.value[x]); | ||
| } else if (object.value[x].nodeType == _node2.default.TEXT_NODE) { | ||
| } else if (object.value[x].nodeType == _node.default.TEXT_NODE) { | ||
| value += object.value[x].nodeValue; | ||
| } | ||
| } | ||
| p.objects.push({ type: object.type, value: value, language: object.language }); | ||
| p.objects.push({ | ||
| type: object.type, | ||
| value: value, | ||
| language: object.language | ||
| }); | ||
| } else if (object.type == RDFaProcessor.HTMLLiteralURI) { | ||
| var value = object.value.length == 0 ? "" : object.value[0].parentNode.innerHTML; | ||
| p.objects.push({ type: object.type, value: value, language: object.language }); | ||
| p.objects.push({ | ||
| type: object.type, | ||
| value: value, | ||
| language: object.language | ||
| }); | ||
| } else { | ||
| p.objects.push({ type: object.type, value: object.value, language: object.language }); | ||
| p.objects.push({ | ||
| type: object.type, | ||
| value: object.value, | ||
| language: object.language | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| return o; | ||
| } | ||
| }, { | ||
| key: 'getValues', | ||
| key: "getValues", | ||
| value: function getValues() { | ||
| var values = []; | ||
| for (var i = 0; i < arguments.length; i++) { | ||
| var property = this.graph.curieParser.parse(arguments[i], true); | ||
| var pnode = this.predicates[property]; | ||
| if (pnode) { | ||
@@ -403,2 +491,3 @@ for (var j = 0; j < pnode.objects.length; j++) { | ||
| } | ||
| return values; | ||
@@ -411,5 +500,8 @@ } | ||
| exports.RDFaSubject = RDFaSubject; | ||
| ; | ||
| var RDFaPredicate = exports.RDFaPredicate = function () { | ||
| var RDFaPredicate = | ||
| /*#__PURE__*/ | ||
| function () { | ||
| function RDFaPredicate(predicate) { | ||
@@ -424,7 +516,9 @@ _classCallCheck(this, RDFaPredicate); | ||
| _createClass(RDFaPredicate, [{ | ||
| key: 'toString', | ||
| key: "toString", | ||
| value: function toString(options) { | ||
| var s = null; | ||
| if (options && options.shorten && options.graph) { | ||
| s = options.graph.shorten(this.predicate, options.prefixesUsed); | ||
| if (!s) { | ||
@@ -436,3 +530,5 @@ s = "<" + this.predicate + ">"; | ||
| } | ||
| s += " "; | ||
| for (var i = 0; i < this.objects.length; i++) { | ||
@@ -442,2 +538,3 @@ if (i > 0) { | ||
| } | ||
| if (this.objects[i].type == "http://www.w3.org/1999/02/22-rdf-syntax-ns#object") { | ||
@@ -452,2 +549,3 @@ if (this.objects[i].value.substring(0, 2) == "_:") { | ||
| u = options.graph.shorten(this.objects[i].value, options.prefixesUsed); | ||
| if (u) { | ||
@@ -462,23 +560,29 @@ s += u; | ||
| } else if (this.objects[i].type == "http://www.w3.org/2001/XMLSchema#integer" || this.objects[i].type == "http://www.w3.org/2001/XMLSchema#decimal" || this.objects[i].type == "http://www.w3.org/2001/XMLSchema#double" || this.objects[i].type == "http://www.w3.org/2001/XMLSchema#boolean") { | ||
| s += this.objects[i].value; | ||
| s += '"' + this.objects[i].value + '"' + "^^<" + this.objects[i].type + ">"; | ||
| } else if (this.objects[i].type == "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral") { | ||
| var serializer = new XMLSerializer(); | ||
| var value = ""; | ||
| for (var x = 0; x < this.objects[i].value.length; x++) { | ||
| if (this.objects[i].value[x].nodeType == _node2.default.ELEMENT_NODE) { | ||
| if (this.objects[i].value[x].nodeType == _node.default.ELEMENT_NODE) { | ||
| var prefixMap = RDFaPredicate.getPrefixMap(this.objects[i].value[x]); | ||
| var prefixes = []; | ||
| for (var prefix in prefixMap) { | ||
| prefixes.push(prefix); | ||
| } | ||
| prefixes.sort(); | ||
| var e = this.objects[i].value[x].cloneNode(true); | ||
| for (var p = 0; p < prefixes.length; p++) { | ||
| e.setAttributeNS("http://www.w3.org/2000/xmlns/", prefixes[p].length == 0 ? "xmlns" : "xmlns:" + prefixes[p], prefixMap[prefixes[p]]); | ||
| } | ||
| value += serializer.serializeToString(e); | ||
| } else if (this.objects[i].value[x].nodeType == _node2.default.TEXT_NODE) { | ||
| } else if (this.objects[i].value[x].nodeType == _node.default.TEXT_NODE) { | ||
| value += this.objects[i].value[x].nodeValue; | ||
| } | ||
| } | ||
| s += '"""' + value.replace(/"""/g, "\\\"\\\"\\\"") + '"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>'; | ||
@@ -494,2 +598,3 @@ } else if (this.objects[i].type == "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML") { | ||
| var l = this.objects[i].value.toString(); | ||
| if (l.indexOf("\n") >= 0 || l.indexOf("\r") >= 0) { | ||
@@ -500,2 +605,3 @@ s += '"""' + l.replace(/"""/g, "\\\"\\\"\\\"") + '"""'; | ||
| } | ||
| if (this.objects[i].type != "http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral") { | ||
@@ -508,2 +614,3 @@ s += "^^<" + this.objects[i].type + ">"; | ||
| } | ||
| return s; | ||
@@ -516,2 +623,3 @@ } | ||
| exports.RDFaPredicate = RDFaPredicate; | ||
| ; | ||
@@ -521,2 +629,3 @@ | ||
| var prefixMap = {}; | ||
| while (e.attributes) { | ||
@@ -526,5 +635,7 @@ for (var i = 0; i < e.attributes.length; i++) { | ||
| var prefix = e.attributes[i].localName; | ||
| if (e.attributes[i].localName == "xmlns") { | ||
| prefix = ""; | ||
| } | ||
| if (!(prefix in prefixMap)) { | ||
@@ -535,5 +646,7 @@ prefixMap[prefix] = e.attributes[i].nodeValue; | ||
| } | ||
| e = e.parentNode; | ||
| } | ||
| return prefixMap; | ||
| }; |
+352
-142
@@ -1,2 +0,2 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
@@ -6,28 +6,39 @@ Object.defineProperty(exports, "__esModule", { | ||
| }); | ||
| exports.default = void 0; | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
| var _uriResolver = _interopRequireDefault(require("./uri-resolver")); | ||
| var _uriResolver = require('./uri-resolver'); | ||
| var _node = _interopRequireDefault(require("./node")); | ||
| var _uriResolver2 = _interopRequireDefault(_uriResolver); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| var _node = require('./node'); | ||
| function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| var _node2 = _interopRequireDefault(_node); | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
| function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
| function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
| function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
| function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
| var RDFaProcessor = function (_URIResolver) { | ||
| function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
| function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
| function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
| var RDFaProcessor = | ||
| /*#__PURE__*/ | ||
| function (_URIResolver) { | ||
| _inherits(RDFaProcessor, _URIResolver); | ||
| function RDFaProcessor(targetObject) { | ||
| var _this; | ||
| _classCallCheck(this, RDFaProcessor); | ||
| var _this = _possibleConstructorReturn(this, (RDFaProcessor.__proto__ || Object.getPrototypeOf(RDFaProcessor)).call(this)); | ||
| _this = _possibleConstructorReturn(this, _getPrototypeOf(RDFaProcessor).call(this)); | ||
@@ -45,2 +56,3 @@ if (targetObject) { | ||
| } | ||
| _this.theOne = "_:" + new Date().getTime(); | ||
@@ -50,7 +62,12 @@ _this.language = null; | ||
| _this.blankCounter = 0; | ||
| _this.langAttributes = [{ namespaceURI: "http://www.w3.org/XML/1998/namespace", localName: "lang" }]; | ||
| _this.langAttributes = [{ | ||
| namespaceURI: "http://www.w3.org/XML/1998/namespace", | ||
| localName: "lang" | ||
| }]; | ||
| _this.inXHTMLMode = false; | ||
| _this.absURIRE = /[\w\_\-]+:\S+/; | ||
| _this.finishedHandlers = []; | ||
| _this.init(); | ||
| return _this; | ||
@@ -60,3 +77,3 @@ } | ||
| _createClass(RDFaProcessor, [{ | ||
| key: 'newBlankNode', | ||
| key: "newBlankNode", | ||
| value: function newBlankNode() { | ||
@@ -67,3 +84,3 @@ this.blankCounter++; | ||
| }, { | ||
| key: 'tokenize', | ||
| key: "tokenize", | ||
| value: function tokenize(str) { | ||
@@ -73,11 +90,14 @@ return RDFaProcessor.trim(str).split(/\s+/); | ||
| }, { | ||
| key: 'parseSafeCURIEOrCURIEOrURI', | ||
| key: "parseSafeCURIEOrCURIEOrURI", | ||
| value: function parseSafeCURIEOrCURIEOrURI(value, prefixes, base) { | ||
| value = RDFaProcessor.trim(value); | ||
| if (value.charAt(0) == '[' && value.charAt(value.length - 1) == ']') { | ||
| value = value.substring(1, value.length - 1); | ||
| value = value.trim(value); | ||
| if (value.length == 0) { | ||
| return null; | ||
| } | ||
| if (value == "_:") { | ||
@@ -87,2 +107,3 @@ // the one node | ||
| } | ||
| return this.parseCURIE(value, prefixes, base); | ||
@@ -94,7 +115,9 @@ } else { | ||
| }, { | ||
| key: 'parseCURIE', | ||
| key: "parseCURIE", | ||
| value: function parseCURIE(value, prefixes, base) { | ||
| var colon = value.indexOf(":"); | ||
| if (colon >= 0) { | ||
| var prefix = value.substring(0, colon); | ||
| if (prefix == "") { | ||
@@ -109,2 +132,3 @@ // default prefix | ||
| var uri = prefixes[prefix]; | ||
| if (uri) { | ||
@@ -115,15 +139,18 @@ return uri + value.substring(colon + 1); | ||
| } | ||
| return null; | ||
| } | ||
| }, { | ||
| key: 'parseCURIEOrURI', | ||
| key: "parseCURIEOrURI", | ||
| value: function parseCURIEOrURI(value, prefixes, base) { | ||
| var curie = this.parseCURIE(value, prefixes, base); | ||
| if (curie) { | ||
| return curie; | ||
| } | ||
| return this.resolveAndNormalize(base, value); | ||
| } | ||
| }, { | ||
| key: 'parsePredicate', | ||
| key: "parsePredicate", | ||
| value: function parsePredicate(value, defaultVocabulary, terms, prefixes, base, ignoreTerms) { | ||
@@ -133,10 +160,13 @@ if (value == "") { | ||
| } | ||
| var predicate = this.parseTermOrCURIEOrAbsURI(value, defaultVocabulary, ignoreTerms ? null : terms, prefixes, base); | ||
| if (predicate && predicate.indexOf("_:") == 0) { | ||
| return null; | ||
| } | ||
| return predicate; | ||
| } | ||
| }, { | ||
| key: 'parseTermOrCURIEOrURI', | ||
| key: "parseTermOrCURIEOrURI", | ||
| value: function parseTermOrCURIEOrURI(value, defaultVocabulary, terms, prefixes, base) { | ||
@@ -146,2 +176,3 @@ //alert("Parsing "+value+" with default vocab "+defaultVocabulary); | ||
| var curie = this.parseCURIE(value, prefixes, base); | ||
| if (curie) { | ||
@@ -151,10 +182,14 @@ return curie; | ||
| var term = terms[value]; | ||
| if (term) { | ||
| return term; | ||
| } | ||
| var lcvalue = value.toLowerCase(); | ||
| term = terms[lcvalue]; | ||
| if (term) { | ||
| return term; | ||
| } | ||
| if (defaultVocabulary && !this.absURIRE.exec(value)) { | ||
@@ -164,6 +199,7 @@ return defaultVocabulary + value; | ||
| } | ||
| return this.resolveAndNormalize(base, value); | ||
| } | ||
| }, { | ||
| key: 'parseTermOrCURIEOrAbsURI', | ||
| key: "parseTermOrCURIEOrAbsURI", | ||
| value: function parseTermOrCURIEOrAbsURI(value, defaultVocabulary, terms, prefixes, base) { | ||
@@ -173,2 +209,3 @@ //alert("Parsing "+value+" with default vocab "+defaultVocabulary); | ||
| var curie = this.parseCURIE(value, prefixes, base); | ||
| if (curie) { | ||
@@ -180,8 +217,12 @@ return curie; | ||
| } | ||
| var term = terms[value]; | ||
| if (term) { | ||
| return term; | ||
| } | ||
| var lcvalue = value.toLowerCase(); | ||
| term = terms[lcvalue]; | ||
| if (term) { | ||
@@ -191,9 +232,11 @@ return term; | ||
| } | ||
| if (this.absURIRE.exec(value)) { | ||
| return this.resolveAndNormalize(base, value); | ||
| } | ||
| return null; | ||
| } | ||
| }, { | ||
| key: 'resolveAndNormalize', | ||
| key: "resolveAndNormalize", | ||
| value: function resolveAndNormalize(base, href) { | ||
@@ -206,3 +249,3 @@ var u = base.resolve(href); | ||
| }, { | ||
| key: 'parsePrefixMappings', | ||
| key: "parsePrefixMappings", | ||
| value: function parsePrefixMappings(str, target) { | ||
@@ -212,2 +255,3 @@ var values = this.tokenize(str); | ||
| var uri = null; | ||
| for (var i = 0; i < values.length; i++) { | ||
@@ -223,22 +267,26 @@ if (values[i][values[i].length - 1] == ':') { | ||
| }, { | ||
| key: 'copyMappings', | ||
| key: "copyMappings", | ||
| value: function copyMappings(mappings) { | ||
| var newMappings = {}; | ||
| for (var k in mappings) { | ||
| newMappings[k] = mappings[k]; | ||
| } | ||
| return newMappings; | ||
| } | ||
| }, { | ||
| key: 'ancestorPath', | ||
| key: "ancestorPath", | ||
| value: function ancestorPath(node) { | ||
| var path = ""; | ||
| while (node && node.nodeType != _node2.default.DOCUMENT_NODE) { | ||
| while (node && node.nodeType != _node.default.DOCUMENT_NODE) { | ||
| path = "/" + node.localName + path; | ||
| node = node.parentNode; | ||
| } | ||
| return path; | ||
| } | ||
| }, { | ||
| key: 'setContext', | ||
| key: "setContext", | ||
| value: function setContext(node) { | ||
@@ -266,10 +314,13 @@ // We only recognized XHTML+RDFa 1.1 if the version is set propertyly | ||
| }, { | ||
| key: 'setInitialContext', | ||
| key: "setInitialContext", | ||
| value: function setInitialContext() { | ||
| this.vocabulary = null; | ||
| // By default, the prefixes are terms are loaded to the RDFa 1.1. standard within the graph constructor | ||
| this.langAttributes = [{ namespaceURI: "http://www.w3.org/XML/1998/namespace", localName: "lang" }]; | ||
| this.vocabulary = null; // By default, the prefixes are terms are loaded to the RDFa 1.1. standard within the graph constructor | ||
| this.langAttributes = [{ | ||
| namespaceURI: "http://www.w3.org/XML/1998/namespace", | ||
| localName: "lang" | ||
| }]; | ||
| } | ||
| }, { | ||
| key: 'setXMLContext', | ||
| key: "setXMLContext", | ||
| value: function setXMLContext() { | ||
@@ -281,6 +332,12 @@ this.setInitialContext(); | ||
| }, { | ||
| key: 'setHTMLContext', | ||
| key: "setHTMLContext", | ||
| value: function setHTMLContext() { | ||
| this.setInitialContext(); | ||
| this.langAttributes = [{ namespaceURI: "http://www.w3.org/XML/1998/namespace", localName: "lang" }, { namespaceURI: null, localName: "lang" }]; | ||
| this.langAttributes = [{ | ||
| namespaceURI: "http://www.w3.org/XML/1998/namespace", | ||
| localName: "lang" | ||
| }, { | ||
| namespaceURI: null, | ||
| localName: "lang" | ||
| }]; | ||
| this.inXHTMLMode = false; | ||
@@ -290,13 +347,15 @@ this.inHTMLMode = true; | ||
| }, { | ||
| key: 'setXHTMLContext', | ||
| key: "setXHTMLContext", | ||
| value: function setXHTMLContext() { | ||
| this.setInitialContext(); | ||
| this.inXHTMLMode = true; | ||
| this.inHTMLMode = false; | ||
| this.langAttributes = [{ | ||
| namespaceURI: "http://www.w3.org/XML/1998/namespace", | ||
| localName: "lang" | ||
| }, { | ||
| namespaceURI: null, | ||
| localName: "lang" | ||
| }]; // From http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1 | ||
| this.langAttributes = [{ namespaceURI: "http://www.w3.org/XML/1998/namespace", localName: "lang" }, { namespaceURI: null, localName: "lang" }]; | ||
| // From http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1 | ||
| this.target.graph.terms["alternate"] = "http://www.w3.org/1999/xhtml/vocab#alternate"; | ||
@@ -326,5 +385,4 @@ this.target.graph.terms["appendix"] = "http://www.w3.org/1999/xhtml/vocab#appendix"; | ||
| this.target.graph.terms["up"] = "http://www.w3.org/1999/xhtml/vocab#up"; | ||
| this.target.graph.terms["p3pv1"] = "http://www.w3.org/1999/xhtml/vocab#p3pv1"; | ||
| this.target.graph.terms["p3pv1"] = "http://www.w3.org/1999/xhtml/vocab#p3pv1"; // other | ||
| // other | ||
| this.target.graph.terms["related"] = "http://www.w3.org/1999/xhtml/vocab#related"; | ||
@@ -335,34 +393,44 @@ this.target.graph.terms["role"] = "http://www.w3.org/1999/xhtml/vocab#role"; | ||
| }, { | ||
| key: 'init', | ||
| key: "init", | ||
| value: function init() {} | ||
| }, { | ||
| key: 'newSubjectOrigin', | ||
| key: "newSubjectOrigin", | ||
| value: function newSubjectOrigin(origin, subject) {} | ||
| }, { | ||
| key: 'addTriple', | ||
| key: "addTriple", | ||
| value: function addTriple(origin, subject, predicate, object) {} | ||
| }, { | ||
| key: 'process', | ||
| key: "process", | ||
| value: function process(node, options) { | ||
| if (node.nodeType == _node2.default.DOCUMENT_NODE) { | ||
| if (node.nodeType == _node.default.DOCUMENT_NODE) { | ||
| node = node.documentElement; | ||
| this.setContext(node); | ||
| } else if (node.parentNode.nodeType == _node2.default.DOCUMENT_NODE) { | ||
| } else if (node.parentNode.nodeType == _node.default.DOCUMENT_NODE) { | ||
| this.setContext(node); | ||
| } | ||
| var queue = []; | ||
| // Fix for Firefox that includes the hash in the base URI | ||
| var queue = []; // Fix for Firefox that includes the hash in the base URI | ||
| var removeHash = function removeHash(baseURI) { | ||
| var hash = baseURI.indexOf("#"); | ||
| if (hash >= 0) { | ||
| baseURI = baseURI.substring(0, hash); | ||
| } | ||
| if (options && options.baseURIMap) { | ||
| baseURI = options.baseURIMap(baseURI); | ||
| } | ||
| return baseURI; | ||
| }; | ||
| queue.push({ current: node, context: this.push(null, removeHash(node.baseURI)) }); | ||
| queue.push({ | ||
| current: node, | ||
| context: this.push(null, removeHash(node.baseURI)) | ||
| }); | ||
| while (queue.length > 0) { | ||
| var item = queue.shift(); | ||
| if (item.parent) { | ||
@@ -373,29 +441,43 @@ // Sequence Step 14: list triple generation | ||
| continue; | ||
| } | ||
| //console.log("Generating lists for "+item.subject+", tag "+item.parent.localName); | ||
| } //console.log("Generating lists for "+item.subject+", tag "+item.parent.localName); | ||
| for (var predicate in item.listMapping) { | ||
| var list = item.listMapping[predicate]; | ||
| if (list.length == 0) { | ||
| this.addTriple(item.parent, item.subject, predicate, { type: RDFaProcessor.objectURI, value: "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" }); | ||
| this.addTriple(item.parent, item.subject, predicate, { | ||
| type: RDFaProcessor.objectURI, | ||
| value: "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" | ||
| }); | ||
| continue; | ||
| } | ||
| var bnodes = []; | ||
| for (var i = 0; i < list.length; i++) { | ||
| bnodes.push(this.newBlankNode()); | ||
| //this.newSubject(item.parent,bnodes[i]); | ||
| bnodes.push(this.newBlankNode()); //this.newSubject(item.parent,bnodes[i]); | ||
| } | ||
| for (var i = 0; i < bnodes.length; i++) { | ||
| this.addTriple(item.parent, bnodes[i], "http://www.w3.org/1999/02/22-rdf-syntax-ns#first", list[i]); | ||
| this.addTriple(item.parent, bnodes[i], "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest", { type: RDFaProcessor.objectURI, value: i + 1 < bnodes.length ? bnodes[i + 1] : "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" }); | ||
| this.addTriple(item.parent, bnodes[i], "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest", { | ||
| type: RDFaProcessor.objectURI, | ||
| value: i + 1 < bnodes.length ? bnodes[i + 1] : "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" | ||
| }); | ||
| } | ||
| this.addTriple(item.parent, item.subject, predicate, { type: RDFaProcessor.objectURI, value: bnodes[0] }); | ||
| this.addTriple(item.parent, item.subject, predicate, { | ||
| type: RDFaProcessor.objectURI, | ||
| value: bnodes[0] | ||
| }); | ||
| } | ||
| continue; | ||
| } | ||
| var current = item.current; | ||
| var context = item.context; | ||
| var context = item.context; //console.log("Tag: "+current.localName+", listMapping="+JSON.stringify(context.listMapping)); | ||
| // Sequence Step 1 | ||
| //console.log("Tag: "+current.localName+", listMapping="+JSON.stringify(context.listMapping)); | ||
| // Sequence Step 1 | ||
| var skip = false; | ||
@@ -411,6 +493,6 @@ var newSubject = null; | ||
| var language = context.language; | ||
| var vocabulary = context.vocabulary; | ||
| var vocabulary = context.vocabulary; // TODO: the "base" element may be used for HTML+RDFa 1.1 | ||
| // TODO: the "base" element may be used for HTML+RDFa 1.1 | ||
| var base; | ||
| if (!current.baseURI) { | ||
@@ -432,23 +514,27 @@ if (this.target.baseURI) { | ||
| current.item = null; | ||
| current.item = null; // Sequence Step 2: set the default vocabulary | ||
| // Sequence Step 2: set the default vocabulary | ||
| var vocabAtt = current.getAttributeNode("vocab"); | ||
| if (vocabAtt) { | ||
| var value = RDFaProcessor.trim(vocabAtt.value); | ||
| if (value.length > 0) { | ||
| vocabulary = value; | ||
| var baseSubject = base.spec; | ||
| //this.newSubject(current,baseSubject); | ||
| this.addTriple(current, baseSubject, "http://www.w3.org/ns/rdfa#usesVocabulary", { type: RDFaProcessor.objectURI, value: vocabulary }); | ||
| var baseSubject = base.spec; //this.newSubject(current,baseSubject); | ||
| this.addTriple(current, baseSubject, "http://www.w3.org/ns/rdfa#usesVocabulary", { | ||
| type: RDFaProcessor.objectURI, | ||
| value: vocabulary | ||
| }); | ||
| } else { | ||
| vocabulary = this.vocabulary; | ||
| } | ||
| } | ||
| } // Sequence Step 3: IRI mappings | ||
| // handle xmlns attributes | ||
| // Sequence Step 3: IRI mappings | ||
| // handle xmlns attributes | ||
| for (var i = 0; i < current.attributes.length; i++) { | ||
| var att = current.attributes[i]; | ||
| //if (att.namespaceURI=="http://www.w3.org/2000/xmlns/") { | ||
| var att = current.attributes[i]; //if (att.namespaceURI=="http://www.w3.org/2000/xmlns/") { | ||
| if (att.name.charAt(0) == "x" && att.name.indexOf("xmlns:") == 0) { | ||
@@ -459,10 +545,13 @@ if (!prefixesCopied) { | ||
| } | ||
| var prefix = att.name.substring(6); | ||
| // TODO: resolve relative? | ||
| var prefix = att.name.substring(6); // TODO: resolve relative? | ||
| var ref = RDFaProcessor.trim(att.value); | ||
| prefixes[prefix] = this.target.baseURI ? this.target.baseURI.resolve(ref) : ref; | ||
| } | ||
| } | ||
| // Handle prefix mappings (@prefix) | ||
| } // Handle prefix mappings (@prefix) | ||
| var prefixAtt = current.getAttributeNode("prefix"); | ||
| if (prefixAtt) { | ||
@@ -473,12 +562,16 @@ if (!prefixesCopied) { | ||
| } | ||
| this.parsePrefixMappings(prefixAtt.value, prefixes); | ||
| } | ||
| } // Sequence Step 4: language | ||
| // Sequence Step 4: language | ||
| var xmlLangAtt = null; | ||
| for (var i = 0; !xmlLangAtt && i < this.langAttributes.length; i++) { | ||
| xmlLangAtt = current.getAttributeNodeNS(this.langAttributes[i].namespaceURI, this.langAttributes[i].localName); | ||
| } | ||
| if (xmlLangAtt) { | ||
| var value = RDFaProcessor.trim(xmlLangAtt.value); | ||
| if (value.length > 0) { | ||
@@ -503,8 +596,10 @@ language = value; | ||
| var inlistAtt = current.getAttributeNode("inlist"); | ||
| var relAttPredicates = []; | ||
| var relAttPredicates = []; | ||
| if (relAtt) { | ||
| var values = this.tokenize(relAtt.value); | ||
| for (var i = 0; i < values.length; i++) { | ||
| var predicate = this.parsePredicate(values[i], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt != null); | ||
| if (predicate) { | ||
@@ -515,7 +610,11 @@ relAttPredicates.push(predicate); | ||
| } | ||
| var revAttPredicates = []; | ||
| if (revAtt) { | ||
| var values = this.tokenize(revAtt.value); | ||
| for (var i = 0; i < values.length; i++) { | ||
| var predicate = this.parsePredicate(values[i], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt != null); | ||
| if (predicate) { | ||
@@ -525,5 +624,5 @@ revAttPredicates.push(predicate); | ||
| } | ||
| } | ||
| } // Section 3.1, bullet 7 | ||
| // Section 3.1, bullet 7 | ||
| if (this.inHTMLMode && (relAtt != null || revAtt != null) && propertyAtt != null) { | ||
@@ -533,2 +632,3 @@ if (relAttPredicates.length == 0) { | ||
| } | ||
| if (revAttPredicates.length == 0) { | ||
@@ -544,7 +644,9 @@ revAtt = null; | ||
| } | ||
| if (typeofAtt) { | ||
| typedResource = newSubject; | ||
| } | ||
| if (!newSubject) { | ||
| if (current.parentNode.nodeType == _node2.default.DOCUMENT_NODE) { | ||
| if (current.parentNode.nodeType == _node.default.DOCUMENT_NODE) { | ||
| newSubject = removeHash(current.baseURI); | ||
@@ -556,2 +658,3 @@ } else if (context.parentObject) { | ||
| } | ||
| if (resourceAtt) { | ||
@@ -570,2 +673,3 @@ currentObjectResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base); | ||
| } | ||
| if (typeofAtt && !aboutAtt && this.inXHTMLMode && (current.localName == "head" || current.localName == "body")) { | ||
@@ -580,2 +684,3 @@ typedResource = newSubject; | ||
| newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base); | ||
| if (typeofAtt) { | ||
@@ -585,4 +690,6 @@ typedResource = newSubject; | ||
| } | ||
| if (!newSubject && current.parentNode.nodeType == _node2.default.DOCUMENT_NODE) { | ||
| if (!newSubject && current.parentNode.nodeType == _node.default.DOCUMENT_NODE) { | ||
| newSubject = removeHash(current.baseURI); | ||
| if (typeofAtt) { | ||
@@ -595,2 +702,3 @@ typedResource = newSubject; | ||
| } | ||
| if (typeofAtt && !typedResource) { | ||
@@ -600,17 +708,22 @@ if (resourceAtt) { | ||
| } | ||
| if (!typedResource && hrefAtt) { | ||
| typedResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value)); | ||
| } | ||
| if (!typedResource && srcAtt) { | ||
| typedResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value)); | ||
| } | ||
| if (!typedResource && (this.inXHTMLMode || this.inHTMLMode) && (current.localName == "head" || current.localName == "body")) { | ||
| typedResource = newSubject; | ||
| } | ||
| if (!typedResource) { | ||
| typedResource = this.newBlankNode(); | ||
| } | ||
| currentObjectResource = typedResource; | ||
| } | ||
| //console.log(current.localName+", newSubject="+newSubject+", typedResource="+typedResource+", currentObjectResource="+currentObjectResource); | ||
| } //console.log(current.localName+", newSubject="+newSubject+", typedResource="+typedResource+", currentObjectResource="+currentObjectResource); | ||
| } else { | ||
@@ -621,13 +734,17 @@ // Sequence Step 5.2: establish a new subject | ||
| } | ||
| if (!newSubject && resourceAtt) { | ||
| newSubject = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base); | ||
| } | ||
| if (!newSubject && hrefAtt) { | ||
| newSubject = this.resolveAndNormalize(base, encodeURI(hrefAtt.value)); | ||
| } | ||
| if (!newSubject && srcAtt) { | ||
| newSubject = this.resolveAndNormalize(base, encodeURI(srcAtt.value)); | ||
| } | ||
| if (!newSubject) { | ||
| if (current.parentNode.nodeType == _node2.default.DOCUMENT_NODE) { | ||
| if (current.parentNode.nodeType == _node.default.DOCUMENT_NODE) { | ||
| newSubject = removeHash(current.baseURI); | ||
@@ -641,2 +758,3 @@ } else if ((this.inXHTMLMode || this.inHTMLMode) && (current.localName == "head" || current.localName == "body")) { | ||
| newSubject = removeHash(current.parentNode.baseURI) == context.parentObject ? removeHash(current.baseURI) : context.parentObject; | ||
| if (!propertyAtt) { | ||
@@ -647,10 +765,11 @@ skip = true; | ||
| } | ||
| if (typeofAtt) { | ||
| typedResource = newSubject; | ||
| } | ||
| } | ||
| } //console.log(current.tagName+": newSubject="+newSubject+", currentObjectResource="+currentObjectResource+", typedResource="+typedResource+", skip="+skip); | ||
| //console.log(current.tagName+": newSubject="+newSubject+", currentObjectResource="+currentObjectResource+", typedResource="+typedResource+", skip="+skip); | ||
| var rdfaData = null; | ||
| if (newSubject) { | ||
@@ -660,23 +779,30 @@ //this.newSubject(current,newSubject); | ||
| var id = newSubject; | ||
| if (typeofAtt && !aboutAtt && !resourceAtt && currentObjectResource) { | ||
| id = currentObjectResource; | ||
| } | ||
| //console.log("Setting data attribute for "+current.localName+" for subject "+id); | ||
| } //console.log("Setting data attribute for "+current.localName+" for subject "+id); | ||
| this.newSubjectOrigin(current, id); | ||
| } | ||
| } | ||
| } // Sequence Step 7: generate type triple | ||
| // Sequence Step 7: generate type triple | ||
| if (typedResource) { | ||
| var values = this.tokenize(typeofAtt.value); | ||
| for (var i = 0; i < values.length; i++) { | ||
| var object = this.parseTermOrCURIEOrAbsURI(values[i], vocabulary, context.terms, prefixes, base); | ||
| if (object) { | ||
| this.addTriple(current, typedResource, RDFaProcessor.typeURI, { type: RDFaProcessor.objectURI, value: object }); | ||
| this.addTriple(current, typedResource, RDFaProcessor.typeURI, { | ||
| type: RDFaProcessor.objectURI, | ||
| value: object | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } // Sequence Step 8: new list mappings if there is a new subject | ||
| //console.log("Step 8: newSubject="+newSubject+", context.parentObject="+context.parentObject); | ||
| // Sequence Step 8: new list mappings if there is a new subject | ||
| //console.log("Step 8: newSubject="+newSubject+", context.parentObject="+context.parentObject); | ||
| if (newSubject && newSubject != context.parentObject) { | ||
@@ -686,5 +812,5 @@ //console.log("Generating new list mapping for "+newSubject); | ||
| listMappingDifferent = true; | ||
| } | ||
| } // Sequence Step 9: generate object triple | ||
| // Sequence Step 9: generate object triple | ||
| if (currentObjectResource) { | ||
@@ -694,2 +820,3 @@ if (relAtt && inlistAtt) { | ||
| var list = listMapping[relAttPredicates[i]]; | ||
| if (!list) { | ||
@@ -699,12 +826,23 @@ list = []; | ||
| } | ||
| list.push({ type: RDFaProcessor.objectURI, value: currentObjectResource }); | ||
| list.push({ | ||
| type: RDFaProcessor.objectURI, | ||
| value: currentObjectResource | ||
| }); | ||
| } | ||
| } else if (relAtt) { | ||
| for (var i = 0; i < relAttPredicates.length; i++) { | ||
| this.addTriple(current, newSubject, relAttPredicates[i], { type: RDFaProcessor.objectURI, value: currentObjectResource }); | ||
| this.addTriple(current, newSubject, relAttPredicates[i], { | ||
| type: RDFaProcessor.objectURI, | ||
| value: currentObjectResource | ||
| }); | ||
| } | ||
| } | ||
| if (revAtt) { | ||
| for (var i = 0; i < revAttPredicates.length; i++) { | ||
| this.addTriple(current, currentObjectResource, revAttPredicates[i], { type: RDFaProcessor.objectURI, value: newSubject }); | ||
| this.addTriple(current, currentObjectResource, revAttPredicates[i], { | ||
| type: RDFaProcessor.objectURI, | ||
| value: newSubject | ||
| }); | ||
| } | ||
@@ -715,33 +853,47 @@ } | ||
| if (newSubject && !currentObjectResource && (relAtt || revAtt)) { | ||
| currentObjectResource = this.newBlankNode(); | ||
| //alert(current.tagName+": generated blank node, newSubject="+newSubject+" currentObjectResource="+currentObjectResource); | ||
| currentObjectResource = this.newBlankNode(); //alert(current.tagName+": generated blank node, newSubject="+newSubject+" currentObjectResource="+currentObjectResource); | ||
| } | ||
| if (relAtt && inlistAtt) { | ||
| for (var i = 0; i < relAttPredicates.length; i++) { | ||
| var list = listMapping[relAttPredicates[i]]; | ||
| if (!list) { | ||
| list = []; | ||
| listMapping[predicate] = list; | ||
| } | ||
| //console.log("Adding incomplete list for "+predicate); | ||
| incomplete.push({ predicate: relAttPredicates[i], list: list }); | ||
| } //console.log("Adding incomplete list for "+predicate); | ||
| incomplete.push({ | ||
| predicate: relAttPredicates[i], | ||
| list: list | ||
| }); | ||
| } | ||
| } else if (relAtt) { | ||
| for (var i = 0; i < relAttPredicates.length; i++) { | ||
| incomplete.push({ predicate: relAttPredicates[i], forward: true }); | ||
| incomplete.push({ | ||
| predicate: relAttPredicates[i], | ||
| forward: true | ||
| }); | ||
| } | ||
| } | ||
| if (revAtt) { | ||
| for (var i = 0; i < revAttPredicates.length; i++) { | ||
| incomplete.push({ predicate: revAttPredicates[i], forward: false }); | ||
| incomplete.push({ | ||
| predicate: revAttPredicates[i], | ||
| forward: false | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } // Step 11: Current property values | ||
| // Step 11: Current property values | ||
| if (propertyAtt) { | ||
| var datatype = null; | ||
| var content = null; | ||
| if (datatypeAtt) { | ||
| datatype = datatypeAtt.value == "" ? RDFaProcessor.PlainLiteralURI : this.parseTermOrCURIEOrAbsURI(datatypeAtt.value, vocabulary, context.terms, prefixes, base); | ||
| if (datetimeAtt && !contentAtt) { | ||
@@ -758,2 +910,3 @@ content = datetimeAtt.value; | ||
| datatype = RDFaProcessor.deriveDateTimeType(content); | ||
| if (!datatype) { | ||
@@ -766,2 +919,3 @@ datatype = RDFaProcessor.PlainLiteralURI; | ||
| } | ||
| if (!content && hrefAtt) { | ||
@@ -772,2 +926,3 @@ content = this.resolveAndNormalize(base, encodeURI(hrefAtt.value)); | ||
| } | ||
| if (content) { | ||
@@ -777,2 +932,3 @@ datatype = RDFaProcessor.objectURI; | ||
| } | ||
| if (!datatype) { | ||
@@ -784,5 +940,7 @@ if (typeofAtt && !aboutAtt) { | ||
| content = current.textContent; | ||
| if (this.inHTMLMode && current.localName == "time") { | ||
| datatype = RDFaProcessor.deriveDateTimeType(content); | ||
| } | ||
| if (!datatype) { | ||
@@ -793,8 +951,12 @@ datatype = RDFaProcessor.PlainLiteralURI; | ||
| } | ||
| var values = this.tokenize(propertyAtt.value); | ||
| for (var i = 0; i < values.length; i++) { | ||
| var predicate = this.parsePredicate(values[i], vocabulary, context.terms, prefixes, base); | ||
| if (predicate) { | ||
| if (inlistAtt) { | ||
| var list = listMapping[predicate]; | ||
| if (!list) { | ||
@@ -804,9 +966,23 @@ list = []; | ||
| } | ||
| list.push(datatype == RDFaProcessor.XMLLiteralURI || datatype == RDFaProcessor.HTMLLiteralURI ? { type: datatype, value: current.childNodes } : { type: datatype ? datatype : RDFaProcessor.PlainLiteralURI, value: content, language: language }); | ||
| list.push(datatype == RDFaProcessor.XMLLiteralURI || datatype == RDFaProcessor.HTMLLiteralURI ? { | ||
| type: datatype, | ||
| value: current.childNodes | ||
| } : { | ||
| type: datatype ? datatype : RDFaProcessor.PlainLiteralURI, | ||
| value: content, | ||
| language: language | ||
| }); | ||
| } else { | ||
| if (datatype == RDFaProcessor.XMLLiteralURI || datatype == RDFaProcessor.HTMLLiteralURI) { | ||
| this.addTriple(current, newSubject, predicate, { type: datatype, value: current.childNodes }); | ||
| this.addTriple(current, newSubject, predicate, { | ||
| type: datatype, | ||
| value: current.childNodes | ||
| }); | ||
| } else { | ||
| this.addTriple(current, newSubject, predicate, { type: datatype ? datatype : RDFaProcessor.PlainLiteralURI, value: content, language: language }); | ||
| //console.log(newSubject+" "+predicate+"="+content); | ||
| this.addTriple(current, newSubject, predicate, { | ||
| type: datatype ? datatype : RDFaProcessor.PlainLiteralURI, | ||
| value: content, | ||
| language: language | ||
| }); //console.log(newSubject+" "+predicate+"="+content); | ||
| } | ||
@@ -816,5 +992,5 @@ } | ||
| } | ||
| } | ||
| } // Sequence Step 12: complete incomplete triples with new subject | ||
| // Sequence Step 12: complete incomplete triples with new subject | ||
| if (newSubject && !skip) { | ||
@@ -825,9 +1001,18 @@ for (var i = 0; i < context.incomplete.length; i++) { | ||
| // TODO: it is unclear what to do here | ||
| context.incomplete[i].list.push({ type: RDFaProcessor.objectURI, value: newSubject }); | ||
| context.incomplete[i].list.push({ | ||
| type: RDFaProcessor.objectURI, | ||
| value: newSubject | ||
| }); | ||
| } else if (context.incomplete[i].forward) { | ||
| //console.log(current.tagName+": completing forward triple "+context.incomplete[i].predicate+" with object="+newSubject); | ||
| this.addTriple(current, context.subject, context.incomplete[i].predicate, { type: RDFaProcessor.objectURI, value: newSubject }); | ||
| this.addTriple(current, context.subject, context.incomplete[i].predicate, { | ||
| type: RDFaProcessor.objectURI, | ||
| value: newSubject | ||
| }); | ||
| } else { | ||
| //console.log(current.tagName+": completing reverse triple with object="+context.subject); | ||
| this.addTriple(current, newSubject, context.incomplete[i].predicate, { type: RDFaProcessor.objectURI, value: context.subject }); | ||
| this.addTriple(current, newSubject, context.incomplete[i].predicate, { | ||
| type: RDFaProcessor.objectURI, | ||
| value: context.subject | ||
| }); | ||
| } | ||
@@ -839,7 +1024,8 @@ } | ||
| var listSubject = newSubject; | ||
| if (skip) { | ||
| // TODO: should subject be null? | ||
| childContext = this.push(context, context.subject); | ||
| // TODO: should the entObject be passed along? If not, then intermediary children will keep properties from being associated with incomplete triples. | ||
| childContext = this.push(context, context.subject); // TODO: should the entObject be passed along? If not, then intermediary children will keep properties from being associated with incomplete triples. | ||
| // TODO: Verify: if the current baseURI has changed and the parentObject is the parent's base URI, then the baseURI should change | ||
| childContext.parentObject = removeHash(current.parentNode.baseURI) == context.parentObject ? removeHash(current.baseURI) : context.parentObject; | ||
@@ -855,2 +1041,3 @@ childContext.incomplete = context.incomplete; | ||
| childContext.incomplete = incomplete; | ||
| if (currentObjectResource) { | ||
@@ -862,2 +1049,3 @@ //console.log("Generating new list mapping for "+currentObjectResource); | ||
| } | ||
| childContext.listMapping = listMapping; | ||
@@ -867,10 +1055,20 @@ childContext.language = language; | ||
| } | ||
| if (listMappingDifferent) { | ||
| //console.log("Pushing list parent "+current.localName); | ||
| queue.unshift({ parent: current, context: context, subject: listSubject, listMapping: listMapping }); | ||
| queue.unshift({ | ||
| parent: current, | ||
| context: context, | ||
| subject: listSubject, | ||
| listMapping: listMapping | ||
| }); | ||
| } | ||
| for (var child = current.lastChild; child; child = child.previousSibling) { | ||
| if (child.nodeType == _node2.default.ELEMENT_NODE) { | ||
| if (child.nodeType == _node.default.ELEMENT_NODE) { | ||
| //console.log("Pushing child "+child.localName); | ||
| queue.unshift({ current: child, context: childContext }); | ||
| queue.unshift({ | ||
| current: child, | ||
| context: childContext | ||
| }); | ||
| } | ||
@@ -889,6 +1087,6 @@ } | ||
| }, { | ||
| key: 'copyProperties', | ||
| key: "copyProperties", | ||
| value: function copyProperties() {} | ||
| }, { | ||
| key: 'push', | ||
| key: "push", | ||
| value: function push(parent, subject) { | ||
@@ -910,7 +1108,6 @@ return { | ||
| return RDFaProcessor; | ||
| }(_uriResolver2.default); | ||
| }(_uriResolver.default); | ||
| exports.default = RDFaProcessor; | ||
| ; | ||
| RDFaProcessor.XMLLiteralURI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"; | ||
@@ -921,6 +1118,4 @@ RDFaProcessor.HTMLLiteralURI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"; | ||
| RDFaProcessor.typeURI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; | ||
| RDFaProcessor.nameChar = '[-A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF.0-9\xB7\u0300-\u036F\u203F-\u2040]'; | ||
| RDFaProcessor.nameStartChar = '[A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u0131\u0134-\u013E\u0141-\u0148\u014A-\u017E\u0180-\u01C3\u01CD-\u01F0\u01F4-\u01F5\u01FA-\u0217\u0250-\u02A8\u02BB-\u02C1\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03CE\u03D0-\u03D6\u03DA\u03DC\u03DE\u03E0\u03E2-\u03F3\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E-\u0481\u0490-\u04C4\u04C7-\u04C8\u04CB-\u04CC\u04D0-\u04EB\u04EE-\u04F5\u04F8-\u04F9\u0531-\u0556\u0559\u0561-\u0586\u05D0-\u05EA\u05F0-\u05F2\u0621-\u063A\u0641-\u064A\u0671-\u06B7\u06BA-\u06BE\u06C0-\u06CE\u06D0-\u06D3\u06D5\u06E5-\u06E6\u0905-\u0939\u093D\u0958-\u0961\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8B\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AE0\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B36-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB5\u0BB7-\u0BB9\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CDE\u0CE0-\u0CE1\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D28\u0D2A-\u0D39\u0D60-\u0D61\u0E01-\u0E2E\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EAE\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0F40-\u0F47\u0F49-\u0F69\u10A0-\u10C5\u10D0-\u10F6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110B-\u110C\u110E-\u1112\u113C\u113E\u1140\u114C\u114E\u1150\u1154-\u1155\u1159\u115F-\u1161\u1163\u1165\u1167\u1169\u116D-\u116E\u1172-\u1173\u1175\u119E\u11A8\u11AB\u11AE-\u11AF\u11B7-\u11B8\u11BA\u11BC-\u11C2\u11EB\u11F0\u11F9\u1E00-\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u212E\u2180-\u2182\u3041-\u3094\u30A1-\u30FA\u3105-\u312C\uAC00-\uD7A3\u4E00-\u9FA5\u3007\u3021-\u3029_]'; | ||
| RDFaProcessor.nameChar = "[-A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF.0-9\xB7\u0300-\u036F\u203F-\u2040]"; | ||
| RDFaProcessor.nameStartChar = "[A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u0131\u0134-\u013E\u0141-\u0148\u014A-\u017E\u0180-\u01C3\u01CD-\u01F0\u01F4-\u01F5\u01FA-\u0217\u0250-\u02A8\u02BB-\u02C1\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03CE\u03D0-\u03D6\u03DA\u03DC\u03DE\u03E0\u03E2-\u03F3\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E-\u0481\u0490-\u04C4\u04C7-\u04C8\u04CB-\u04CC\u04D0-\u04EB\u04EE-\u04F5\u04F8-\u04F9\u0531-\u0556\u0559\u0561-\u0586\u05D0-\u05EA\u05F0-\u05F2\u0621-\u063A\u0641-\u064A\u0671-\u06B7\u06BA-\u06BE\u06C0-\u06CE\u06D0-\u06D3\u06D5\u06E5-\u06E6\u0905-\u0939\u093D\u0958-\u0961\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8B\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AE0\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B36-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB5\u0BB7-\u0BB9\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CDE\u0CE0-\u0CE1\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D28\u0D2A-\u0D39\u0D60-\u0D61\u0E01-\u0E2E\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EAE\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0F40-\u0F47\u0F49-\u0F69\u10A0-\u10C5\u10D0-\u10F6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110B-\u110C\u110E-\u1112\u113C\u113E\u1140\u114C\u114E\u1150\u1154-\u1155\u1159\u115F-\u1161\u1163\u1165\u1167\u1169\u116D-\u116E\u1172-\u1173\u1175\u119E\u11A8\u11AB\u11AE-\u11AF\u11B7-\u11B8\u11BA\u11BC-\u11C2\u11EB\u11F0\u11F9\u1E00-\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u212E\u2180-\u2182\u3041-\u3094\u30A1-\u30FA\u3105-\u312C\uAC00-\uD7A3\u4E00-\u9FA5\u3007\u3021-\u3029_]"; | ||
| RDFaProcessor.NCNAME = new RegExp('^' + RDFaProcessor.nameStartChar + RDFaProcessor.nameChar + '*$'); | ||
@@ -932,9 +1127,21 @@ | ||
| RDFaProcessor.dateTimeTypes = [{ pattern: /-?P(?:[0-9]+Y)?(?:[0-9]+M)?(?:[0-9]+D)?(?:T(?:[0-9]+H)?(?:[0-9]+M)?(?:[0-9]+(?:\.[0-9]+)?S)?)?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#duration" }, { pattern: /-?(?:[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9])-[0-9][0-9]-[0-9][0-9]T(?:[0-1][0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?(?:Z|[+\-][0-9][0-9]:[0-9][0-9])?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#dateTime" }, { pattern: /-?(?:[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9])-[0-9][0-9]-[0-9][0-9](?:Z|[+\-][0-9][0-9]:[0-9][0-9])?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#date" }, { pattern: /(?:[0-1][0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?(?:Z|[+\-][0-9][0-9]:[0-9][0-9])?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#time" }, { pattern: /-?(?:[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9])-[0-9][0-9]/, | ||
| type: "http://www.w3.org/2001/XMLSchema#gYearMonth" }, { pattern: /-?[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9]/, | ||
| type: "http://www.w3.org/2001/XMLSchema#gYear" }]; | ||
| RDFaProcessor.dateTimeTypes = [{ | ||
| pattern: /-?P(?:[0-9]+Y)?(?:[0-9]+M)?(?:[0-9]+D)?(?:T(?:[0-9]+H)?(?:[0-9]+M)?(?:[0-9]+(?:\.[0-9]+)?S)?)?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#duration" | ||
| }, { | ||
| pattern: /-?(?:[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9])-[0-9][0-9]-[0-9][0-9]T(?:[0-1][0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?(?:Z|[+\-][0-9][0-9]:[0-9][0-9])?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#dateTime" | ||
| }, { | ||
| pattern: /-?(?:[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9])-[0-9][0-9]-[0-9][0-9](?:Z|[+\-][0-9][0-9]:[0-9][0-9])?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#date" | ||
| }, { | ||
| pattern: /(?:[0-1][0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9](?:\.[0-9]+)?(?:Z|[+\-][0-9][0-9]:[0-9][0-9])?/, | ||
| type: "http://www.w3.org/2001/XMLSchema#time" | ||
| }, { | ||
| pattern: /-?(?:[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9])-[0-9][0-9]/, | ||
| type: "http://www.w3.org/2001/XMLSchema#gYearMonth" | ||
| }, { | ||
| pattern: /-?[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9]/, | ||
| type: "http://www.w3.org/2001/XMLSchema#gYear" | ||
| }]; | ||
@@ -945,2 +1152,3 @@ RDFaProcessor.deriveDateTimeType = function (value) { | ||
| var matched = RDFaProcessor.dateTimeTypes[i].pattern.exec(value); | ||
| if (matched && matched[0].length == value.length) { | ||
@@ -951,4 +1159,6 @@ //console.log("Matched!"); | ||
| } | ||
| return null; | ||
| }; | ||
| module.exports = exports['default']; | ||
| module.exports = exports.default; |
+64
-14
@@ -1,2 +0,2 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
@@ -6,8 +6,13 @@ Object.defineProperty(exports, "__esModule", { | ||
| }); | ||
| exports.default = void 0; | ||
| var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| var URIResolver = function () { | ||
| function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
| function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
| var URIResolver = | ||
| /*#__PURE__*/ | ||
| function () { | ||
| function URIResolver() { | ||
@@ -18,11 +23,16 @@ _classCallCheck(this, URIResolver); | ||
| _createClass(URIResolver, [{ | ||
| key: 'parseURI', | ||
| key: "parseURI", | ||
| value: function parseURI(uri) { | ||
| var match = URIResolver.SCHEME.exec(uri); | ||
| if (!match) { | ||
| throw new Error("Bad URI value, no scheme: " + uri); | ||
| } | ||
| var parsed = { spec: uri }; | ||
| var parsed = { | ||
| spec: uri | ||
| }; | ||
| parsed.scheme = match[0].substring(0, match[0].length - 1); | ||
| parsed.schemeSpecificPart = parsed.spec.substring(match[0].length); | ||
| if (parsed.schemeSpecificPart.charAt(0) == '/' && parsed.schemeSpecificPart.charAt(1) == '/') { | ||
@@ -33,2 +43,3 @@ this.parseGeneric(parsed); | ||
| } | ||
| parsed.normalize = function () { | ||
@@ -38,6 +49,8 @@ if (!this.isGeneric) { | ||
| } | ||
| if (this.segments.length == 0) { | ||
| return; | ||
| } | ||
| // edge case of ending in "/." | ||
| } // edge case of ending in "/." | ||
| if (this.path.length > 1 && this.path.substring(this.path.length - 2) == "/.") { | ||
@@ -47,15 +60,21 @@ this.path = this.path.substring(0, this.path.length - 1); | ||
| this.schemeSpecificPart = "//" + this.authority + this.path; | ||
| if (typeof this.query != "undefined") { | ||
| this.schemeSpecificPart += "?" + this.query; | ||
| } | ||
| if (typeof this.fragment != "undefined") { | ||
| this.schemeSpecificPart += "#" + this.fragment; | ||
| } | ||
| this.spec = this.scheme + ":" + this.schemeSpecificPart; | ||
| return; | ||
| } | ||
| var end = this.path.charAt(this.path.length - 1); | ||
| if (end != "/") { | ||
| end = ""; | ||
| } | ||
| for (var i = 0; i < this.segments.length; i++) { | ||
@@ -66,2 +85,3 @@ if (i > 0 && this.segments[i] == "..") { | ||
| } | ||
| if (this.segments[i] == ".") { | ||
@@ -72,10 +92,14 @@ this.segments.splice(i, 1); | ||
| } | ||
| this.path = this.segments.length == 0 ? "/" : "/" + this.segments.join("/") + end; | ||
| this.schemeSpecificPart = "//" + this.authority + this.path; | ||
| if (typeof this.query != "undefined") { | ||
| this.schemeSpecificPart += "?" + this.query; | ||
| } | ||
| if (typeof this.fragment != "undefined") { | ||
| this.schemeSpecificPart += "#" + this.fragment; | ||
| } | ||
| this.spec = this.scheme + ":" + this.schemeSpecificPart; | ||
@@ -88,2 +112,3 @@ }; | ||
| } | ||
| if (href.charAt(0) == '#') { | ||
@@ -93,6 +118,9 @@ var lastHash = this.spec.lastIndexOf('#'); | ||
| } | ||
| if (!this.isGeneric) { | ||
| throw new Error("Cannot resolve uri against non-generic URI: " + this.spec); | ||
| } | ||
| var colon = href.indexOf(':'); | ||
| if (href.charAt(0) == '/') { | ||
@@ -125,12 +153,17 @@ return this.scheme + "://" + this.authority + href; | ||
| } | ||
| if (!this.isGeneric) { | ||
| throw new Error("A non generic URI cannot be made relative: " + this.spec); | ||
| } | ||
| if (!otherURI.isGeneric) { | ||
| throw new Error("Cannot make a relative URI against a non-generic URI: " + otherURI.spec); | ||
| } | ||
| if (otherURI.authority != this.authority) { | ||
| return this.spec; | ||
| } | ||
| var i = 0; | ||
| for (; i < this.segments.length && i < otherURI.segments.length; i++) { | ||
@@ -141,7 +174,10 @@ if (this.segments[i] != otherURI.segments[i]) { | ||
| var relative = ""; | ||
| for (var j = i; j < otherURI.segments.length + offset; j++) { | ||
| relative += "../"; | ||
| } | ||
| for (var j = i; j < this.segments.length; j++) { | ||
| relative += this.segments[j]; | ||
| if (j + 1 < this.segments.length) { | ||
@@ -151,8 +187,11 @@ relative += "/"; | ||
| } | ||
| if (this.path.charAt(this.path.length - 1) == '/') { | ||
| relative += "/"; | ||
| } | ||
| return relative; | ||
| } | ||
| } | ||
| if (this.segments.length == otherURI.segments.length) { | ||
@@ -162,4 +201,6 @@ return this.hash ? this.hash : this.query ? this.query : ""; | ||
| var relative = ""; | ||
| for (var j = i; j < this.segments.length; j++) { | ||
| relative += this.segments[j]; | ||
| if (j + 1 < this.segments.length) { | ||
@@ -169,5 +210,7 @@ relative += "/"; | ||
| } | ||
| if (this.path.charAt(this.path.length - 1) == '/') { | ||
| relative += "/"; | ||
| } | ||
| return relative; | ||
@@ -178,6 +221,7 @@ } else { | ||
| }; | ||
| return parsed; | ||
| } | ||
| }, { | ||
| key: 'parseGeneric', | ||
| key: "parseGeneric", | ||
| value: function parseGeneric(parsed) { | ||
@@ -193,2 +237,3 @@ if (parsed.schemeSpecificPart.charAt(0) != '/' || parsed.schemeSpecificPart.charAt(1) != '/') { | ||
| var hash = parsed.path.indexOf('#'); | ||
| if (hash >= 0) { | ||
@@ -198,3 +243,5 @@ parsed.fragment = parsed.path.substring(hash + 1); | ||
| } | ||
| var questionMark = parsed.path.indexOf('?'); | ||
| if (questionMark >= 0) { | ||
@@ -204,2 +251,3 @@ parsed.query = parsed.path.substring(questionMark + 1); | ||
| } | ||
| if (parsed.path == "/" || parsed.path == "") { | ||
@@ -209,2 +257,3 @@ parsed.segments = []; | ||
| parsed.segments = parsed.path.split(/\//); | ||
| if (parsed.segments.length > 0 && parsed.segments[0] == '' && parsed.path.length > 1 && parsed.path.charAt(1) != '/') { | ||
@@ -214,2 +263,3 @@ // empty segment at the start, remove it | ||
| } | ||
| if (parsed.segments.length > 0 && parsed.path.length > 0 && parsed.path.charAt(parsed.path.length - 1) == '/' && parsed.segments[parsed.segments.length - 1] == '') { | ||
@@ -221,4 +271,5 @@ // we may have an empty the end | ||
| } | ||
| } | ||
| // check for non-escaped characters | ||
| } // check for non-escaped characters | ||
| for (var i = 0; i < parsed.segments.length; i++) { | ||
@@ -234,2 +285,3 @@ var check = parsed.segments[i].split(/%[A-Za-z0-9][A-Za-z0-9]|[\ud800-\udfff][\ud800-\udfff]|[A-Za-z0-9\-\._~!$&'()*+,;=@:\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/); | ||
| } | ||
| parsed.isGeneric = true; | ||
@@ -243,5 +295,3 @@ } | ||
| exports.default = URIResolver; | ||
| URIResolver.SCHEME = /^[A-Za-z][A-Za-z0-9\+\-\.]*\:/; | ||
| module.exports = exports['default']; | ||
| module.exports = exports.default; |
+19
-12
| { | ||
| "name": "graph-rdfa-processor", | ||
| "version": "1.3.0", | ||
| "version": "2.0.0", | ||
| "description": "Green turtle GraphRdfaProcessor extracted and available as a commonJS module", | ||
@@ -8,8 +8,14 @@ "main": "dist/index.js", | ||
| "scripts": { | ||
| "test": "mocha --compilers js:babel-register", | ||
| "prepublish": "rm -rf dist && babel src --out-dir dist" | ||
| "test": "mocha --require @babel/register --exit", | ||
| "prepare": "rm -rf dist && babel src --out-dir dist", | ||
| "postversion": "git push && git push --tags" | ||
| }, | ||
| "babel": { | ||
| "presets": [ | ||
| "es2015" | ||
| [ | ||
| "@babel/preset-env", | ||
| { | ||
| "targets": "> 0.25%, not dead" | ||
| } | ||
| ] | ||
| ], | ||
@@ -22,3 +28,3 @@ "plugins": [ | ||
| "type": "git", | ||
| "url": "git+https://github.com/scienceai/graph-rdfa-processor.git" | ||
| "url": "git+https://github.com/science-periodicals/graph-rdfa-processor.git" | ||
| }, | ||
@@ -31,13 +37,14 @@ "keywords": [ | ||
| "bugs": { | ||
| "url": "https://github.com/scienceai/graph-rdfa-processor/issues" | ||
| "url": "https://github.com/science-periodicals/graph-rdfa-processor/issues" | ||
| }, | ||
| "homepage": "https://github.com/scienceai/graph-rdfa-processor#readme", | ||
| "homepage": "https://github.com/science-periodicals/graph-rdfa-processor#readme", | ||
| "devDependencies": { | ||
| "babel-cli": "^6.23.0", | ||
| "babel-plugin-add-module-exports": "^0.2.1", | ||
| "babel-preset-es2015": "^6.22.0", | ||
| "babel-register": "^6.23.0", | ||
| "@babel/cli": "^7.5.5", | ||
| "@babel/core": "^7.5.5", | ||
| "@babel/preset-env": "^7.5.5", | ||
| "@babel/register": "^7.5.5", | ||
| "babel-plugin-add-module-exports": "^1.0.2", | ||
| "jsdom": "^9.11.0", | ||
| "mocha": "^3.2.0" | ||
| "mocha": "^6.2.0" | ||
| } | ||
| } |
+7
-2
| # graph-rdfa-processor | ||
| [](https://circleci.com/gh/science-periodicals/graph-rdfa-processor) | ||
| Note: this module is auto published to npm on CircleCI. Only run `npm version | ||
| patch|minor|major` and let CI do the rest. | ||
| Green turtle GraphRdfaProcessor extracted and available as a | ||
@@ -15,3 +20,3 @@ standalone commonJS / ES2015 module. | ||
| ``` | ||
| ```js | ||
| import getRdfaGraph from graph-rdfa-processor; | ||
@@ -29,3 +34,3 @@ | ||
| see | ||
| [jsonld-rdfa-parser](https://github.com/scienceai/jsonld-rdfa-parser) | ||
| [jsonld-rdfa-parser](https://github.com/science-periodicals/jsonld-rdfa-parser) | ||
| (using this module to extract the RDFa graph. |
@@ -381,3 +381,3 @@ import Node from './node'; | ||
| this.objects[i].type=="http://www.w3.org/2001/XMLSchema#boolean") { | ||
| s += this.objects[i].value; | ||
| s += '"' + this.objects[i].value + '"' + "^^<" + this.objects[i].type + ">"; | ||
| } else if (this.objects[i].type=="http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral") { | ||
@@ -384,0 +384,0 @@ var serializer = new XMLSerializer(); |
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
166758
2.73%3520
3.8%35
16.67%4
-20%7
16.67%