single-file-core 1.0.6 → 1.0.7
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/package.json +2 -2
- package/single-file-core.js +15 -0
- package/single-file-helper.js +6 -2
- package/single-file-util.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "single-file-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "SingleFile Core",
|
|
5
5
|
"author": "Gildas Lormeau",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
"url": "https://github.com/gildas-lormeau/single-file-core/issues"
|
|
16
16
|
},
|
|
17
17
|
"homepage": "https://github.com/gildas-lormeau/single-file-core#readme"
|
|
18
|
-
}
|
|
18
|
+
}
|
package/single-file-core.js
CHANGED
|
@@ -95,6 +95,7 @@ const STAGES = [{
|
|
|
95
95
|
{ action: "preProcessPage" },
|
|
96
96
|
{ option: "loadDeferredImagesKeepZoomLevel", action: "resetZoomLevel" },
|
|
97
97
|
{ action: "replaceStyleContents" },
|
|
98
|
+
{ action: "replaceInvalidElements" },
|
|
98
99
|
{ action: "resetCharsetMeta" },
|
|
99
100
|
{ option: "saveFavicon", action: "saveFavicon" },
|
|
100
101
|
{ action: "replaceCanvasElements" },
|
|
@@ -795,6 +796,20 @@ class Processor {
|
|
|
795
796
|
this.doc.querySelectorAll("a[ping]").forEach(element => element.removeAttribute("ping"));
|
|
796
797
|
}
|
|
797
798
|
|
|
799
|
+
replaceInvalidElements() {
|
|
800
|
+
this.doc.querySelectorAll("template[" + util.INVALID_ELEMENT_ATTRIBUTE_NAME + "]").forEach(templateElement => {
|
|
801
|
+
const placeHolderElement = this.doc.createElement("span");
|
|
802
|
+
const originalElement = templateElement.content.firstChild;
|
|
803
|
+
if (originalElement) {
|
|
804
|
+
if (originalElement.hasAttributes()) {
|
|
805
|
+
Array.from(originalElement.attributes).forEach(attribute => placeHolderElement.setAttribute(attribute.name, attribute.value));
|
|
806
|
+
}
|
|
807
|
+
originalElement.childNodes.forEach(childNode => placeHolderElement.appendChild(childNode.cloneNode(true)));
|
|
808
|
+
}
|
|
809
|
+
templateElement.replaceWith(placeHolderElement);
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
|
|
798
813
|
resetCharsetMeta() {
|
|
799
814
|
let charset;
|
|
800
815
|
this.doc.querySelectorAll("meta[charset], meta[http-equiv=\"content-type\"]").forEach(element => {
|
package/single-file-helper.js
CHANGED
|
@@ -46,6 +46,7 @@ const LAZY_SRC_ATTRIBUTE_NAME = "data-single-file-lazy-loaded-src";
|
|
|
46
46
|
const STYLESHEET_ATTRIBUTE_NAME = "data-single-file-stylesheet";
|
|
47
47
|
const DISABLED_NOSCRIPT_ATTRIBUTE_NAME = "data-single-file-disabled-noscript";
|
|
48
48
|
const SELECTED_CONTENT_ATTRIBUTE_NAME = "data-single-file-selected-content";
|
|
49
|
+
const INVALID_ELEMENT_ATTRIBUTE_NAME = "data-single-file-invalid-element";
|
|
49
50
|
const ASYNC_SCRIPT_ATTRIBUTE_NAME = "data-single-file-async-script";
|
|
50
51
|
const FLOW_ELEMENTS_SELECTOR = "*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)";
|
|
51
52
|
const KEPT_TAG_NAMES = ["NOSCRIPT", "DISABLED-NOSCRIPT", "META", "LINK", "STYLE", "TITLE", "TEMPLATE", "SOURCE", "OBJECT", "SCRIPT", "HEAD"];
|
|
@@ -94,6 +95,7 @@ export {
|
|
|
94
95
|
LAZY_SRC_ATTRIBUTE_NAME,
|
|
95
96
|
STYLESHEET_ATTRIBUTE_NAME,
|
|
96
97
|
SELECTED_CONTENT_ATTRIBUTE_NAME,
|
|
98
|
+
INVALID_ELEMENT_ATTRIBUTE_NAME,
|
|
97
99
|
ASYNC_SCRIPT_ATTRIBUTE_NAME,
|
|
98
100
|
COMMENT_HEADER,
|
|
99
101
|
COMMENT_HEADER_LEGACY,
|
|
@@ -138,8 +140,10 @@ function preProcessDoc(doc, win, options) {
|
|
|
138
140
|
const invalidElements = new Map();
|
|
139
141
|
let elementsInfo;
|
|
140
142
|
if (win && doc.documentElement) {
|
|
141
|
-
doc.querySelectorAll("button button").forEach(element => {
|
|
142
|
-
const placeHolderElement = doc.
|
|
143
|
+
doc.querySelectorAll("button button, a a, p div").forEach(element => {
|
|
144
|
+
const placeHolderElement = doc.createElement("template");
|
|
145
|
+
placeHolderElement.setAttribute(INVALID_ELEMENT_ATTRIBUTE_NAME, "");
|
|
146
|
+
placeHolderElement.content.appendChild(element.cloneNode(true));
|
|
143
147
|
invalidElements.set(element, placeHolderElement);
|
|
144
148
|
element.replaceWith(placeHolderElement);
|
|
145
149
|
});
|
package/single-file-util.js
CHANGED
|
@@ -186,6 +186,7 @@ function getInstance(utilOptions) {
|
|
|
186
186
|
PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME: helper.PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
|
|
187
187
|
STYLESHEET_ATTRIBUTE_NAME: helper.STYLESHEET_ATTRIBUTE_NAME,
|
|
188
188
|
SELECTED_CONTENT_ATTRIBUTE_NAME: helper.SELECTED_CONTENT_ATTRIBUTE_NAME,
|
|
189
|
+
INVALID_ELEMENT_ATTRIBUTE_NAME: helper.INVALID_ELEMENT_ATTRIBUTE_NAME,
|
|
189
190
|
COMMENT_HEADER: helper.COMMENT_HEADER,
|
|
190
191
|
COMMENT_HEADER_LEGACY: helper.COMMENT_HEADER_LEGACY,
|
|
191
192
|
SINGLE_FILE_UI_ELEMENT_CLASS: helper.SINGLE_FILE_UI_ELEMENT_CLASS,
|