@ungap/processing-instruction 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/index.js +25 -2
- package/package.json +7 -3
package/README.md
ADDED
package/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// <?t a="b" x="yy"?>
|
|
2
|
-
|
|
3
1
|
const { defineProperty } = Object;
|
|
4
2
|
const { prototype } = ProcessingInstruction;
|
|
5
3
|
const attributes = /(\S+?)=("|')([^\2]*?)\2/g;
|
|
6
4
|
const attribute = name => new RegExp(`(\\s*)\\b${name}\\b=("|')([^\\2]*?)\\2`);
|
|
7
5
|
|
|
6
|
+
// borrowed from html-escaper
|
|
8
7
|
const es = /[&<>"']/g;
|
|
9
8
|
const cape = c => {
|
|
10
9
|
if (c === '&') return '&';
|
|
@@ -51,3 +50,27 @@ for (const [key, value] of [
|
|
|
51
50
|
value
|
|
52
51
|
});
|
|
53
52
|
}
|
|
53
|
+
|
|
54
|
+
const template = document.createElement('template');
|
|
55
|
+
template.innerHTML = '<?t ?>';
|
|
56
|
+
|
|
57
|
+
export default template.content.firstChild.nodeType === Node.COMMENT_NODE ?
|
|
58
|
+
(dom => {
|
|
59
|
+
const tw = document.createTreeWalker(dom, NodeFilter.SHOW_COMMENT);
|
|
60
|
+
let comment;
|
|
61
|
+
while (comment = tw.nextNode()) {
|
|
62
|
+
const { data } = comment;
|
|
63
|
+
if (data.endsWith('?') && /^\?(\S+)/.test(data)) {
|
|
64
|
+
const target = RegExp.$1;
|
|
65
|
+
comment.replaceWith(
|
|
66
|
+
document.createProcessingInstruction(
|
|
67
|
+
target,
|
|
68
|
+
data.slice(1 + target.length, -1).trim()
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return dom;
|
|
74
|
+
}) :
|
|
75
|
+
(dom => dom)
|
|
76
|
+
;
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ungap/processing-instruction",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A polyfill for ProcessingInstruction attributes",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/ungap/processing-instruction.git"
|
|
10
10
|
},
|
|
11
|
-
"keywords": [
|
|
11
|
+
"keywords": [
|
|
12
|
+
"ProcessingInstruction",
|
|
13
|
+
"polyfill",
|
|
14
|
+
"shim"
|
|
15
|
+
],
|
|
12
16
|
"author": "Andrea Giammarchi",
|
|
13
17
|
"license": "MIT",
|
|
14
18
|
"type": "module",
|