Skip to content

Commit feab21c

Browse files
committedApr 1, 2021
resolve rdf:HTML in RDFa
1 parent 1ac11d7 commit feab21c

11 files changed

+6860
-45
lines changed
 

‎package-lock.json

+121-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"test": "npm run test:unit && npm run test:serialize && npm run test:types",
9999
"test:clean": "rimraf tests/serialize/,*",
100100
"test:serialize": "npm run build && npm run test:serialize:all && npm run test:clean",
101-
"test:serialize:all": "npm run test:serialize:1 && npm run test:serialize:2 && npm run test:serialize:3 && npm run test:serialize:4 && npm run test:serialize:5 && npm run test:serialize:6 && npm run test:serialize:7 && npm run test:serialize:10 && npm run test:serialize:11 && npm run test:serialize:12 && npm run test:serialize:13",
101+
"test:serialize:all": "npm run test:serialize:1 && npm run test:serialize:2 && npm run test:serialize:3 && npm run test:serialize:4 && npm run test:serialize:5 && npm run test:serialize:6 && npm run test:serialize:7 && npm run test:serialize:10 && npm run test:serialize:11 && npm run test:serialize:12 && npm run test:serialize:13 && npm run test:serialize:14 && npm run test:serialize:15",
102102
"test:serialize:1": "cd ./tests/serialize && node ./data.js -in=t1.ttl -format=application/rdf+xml -out=,t1.xml && fs-grep http://www.w3.org/2001/XMLSchema#integer ,t1.xml",
103103
"test:serialize:2": "cd ./tests/serialize && node ./data.js -in=t2.ttl -format=application/rdf+xml -out=,t2.xml && node diff ,t2.xml t2-ref.xml",
104104
"test:serialize:3": "cd ./tests/serialize && node ./data.js -in=t3.ttl -format=application/rdf+xml -out=,t3.xml && node diff ,t3.xml t3-ref.xml",
@@ -112,6 +112,8 @@
112112
"test:serialize:11": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=application/rdf+xml -out=,structures.xml && node diff ,structures.xml t11-ref.xml",
113113
"test:serialize:12": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=text/turtle -out=,structures.ttl && node diff ,structures.ttl t12-ref.ttl",
114114
"test:serialize:13": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=application/n-triples -out=,structures.nt && node ./data.js -format=application/n-triples -in=,structures.nt -format=text/turtle -out=,structures.nt.ttl && node diff ,structures.nt.ttl t13-ref.ttl",
115+
"test:serialize:14": "cd ./tests/serialize && node ./data.js -in=t14.html -format=text/turtle -out=,t14.ttl && node diff ,t14.ttl t14-ref.ttl",
116+
"test:serialize:15": "cd ./tests/serialize && node ./data.js -in=t15.html -format=text/turtle -out=,t15.ttl && node diff ,t15.ttl t15-ref.ttl",
115117
"test:types": "tsc --noEmit --target es2019 --moduleResolution node tests/types/*.ts",
116118
"test:unit": "mocha --growl --require ./tests/babel-register.js tests/unit/**-test.*",
117119
"test:unit:egp": "mocha --require ./tests/babel-register.js tests/unit/fetcher-egp-test.js",

‎src/rdfaparser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ export default class RDFaProcessor {
895895
case RDFaProcessor.XMLLiteralURI:
896896
case RDFaProcessor.HTMLLiteralURI:
897897
var string = ''
898-
Object.keys(x.value).forEach(function (i) {
898+
Object.keys(x.value).forEach(i => {
899899
string += Util.domToString(x.value[i], this.htmlOptions)
900900
})
901901
return new Literal(string, '', new NamedNode(x.type))

‎src/utils-js.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ export function DOMParserFactory () {
103103
export function domToString (node, options) {
104104
options = options || {}
105105
var selfClosing = []
106-
if ('selfClosing' in options) {
106+
if (options && options.selfClosing) {
107107
options.selfClosing.split(' ').forEach(function (n) {
108108
selfClosing[n] = true
109109
})
110110
}
111111
var skipAttributes = []
112-
if ('skipAttributes' in options) {
112+
if (options && options.skipAttributes) {
113113
options.skipAttributes.split(' ').forEach(function (n) {
114114
skipAttributes[n] = true
115115
})
@@ -123,34 +123,34 @@ export function dumpNode (node, options, selfClosing, skipAttributes) {
123123
var noEsc = [ false ]
124124
if (typeof node.nodeType === 'undefined') return out
125125
if (node.nodeType === 1) {
126-
if (node.hasAttribute('class') && 'classWithChildText' in options && node.matches(options.classWithChildText.class)) {
126+
if (node.hasAttribute('class') && (options && options.classWithChildText) && node.matches(options.classWithChildText.class)) {
127127
out += node.querySelector(options.classWithChildText.element).textContent
128-
} else if (!('skipNodeWithClass' in options && node.matches('.' + options.skipNodeWithClass))) {
128+
} else if (!((options && options.skipNodeWithClass) && node.matches('.' + options.skipNodeWithClass))) {
129129
var ename = node.nodeName.toLowerCase()
130130
out += '<' + ename
131131

132132
var attrList = []
133133
for (i = node.attributes.length - 1; i >= 0; i--) {
134134
var atn = node.attributes[i]
135-
if (skipAttributes.length > 0 && skipAttributes[atn.name]) continue
135+
if (skipAttributes && skipAttributes.length > 0 && skipAttributes[atn.name]) continue
136136
if (/^\d+$/.test(atn.name)) continue
137-
if (atn.name === 'class' && 'replaceClassItemWith' in options && (atn.value.split(' ').indexOf(options.replaceClassItemWith.source) > -1)) {
137+
if (atn.name === 'class' && (options && options.replaceClassItemWith) && (atn.value.split(' ').indexOf(options.replaceClassItemWith.source) > -1)) {
138138
var re = new RegExp(options.replaceClassItemWith.source, 'g')
139139
atn.value = atn.value.replace(re, options.replaceClassItemWith.target).trim()
140140
}
141-
if (!(atn.name === 'class' && 'skipClassWithValue' in options && options.skipClassWithValue === atn.value)) {
141+
if (!(atn.name === 'class' && (options && options.skipClassWithValue) && options.skipClassWithValue === atn.value)) {
142142
attrList.push(atn.name + '=\'' + atn.value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&quot;') + '\'')
143143
}
144144
}
145145
if (attrList.length > 0) {
146-
if ('sortAttributes' in options && options.sortAttributes) {
146+
if (options && options.sortAttributes) {
147147
attrList.sort(function (a, b) {
148148
return a.toLowerCase().localeCompare(b.toLowerCase())
149149
})
150150
}
151151
out += ' ' + attrList.join(' ')
152152
}
153-
if (selfClosing[ename]) {
153+
if (selfClosing && selfClosing.ename) {
154154
out += ' />'
155155
} else {
156156
out += '>'

‎tests/rdfa/run-rdfa-tests.js

100644100755
File mode changed.

0 commit comments

Comments
 (0)