|
|
@@ -73,17 +73,17 @@ this.singlefile.lib.modules.serializer = this.singlefile.lib.modules.serializer
|
|
|
docTypeString += " [" + docType.internalSubset + "]";
|
|
|
docTypeString += "> ";
|
|
|
}
|
|
|
- return docTypeString + (compressHTML ? serialize(doc.documentElement) : doc.documentElement.outerHTML);
|
|
|
+ return docTypeString + serialize(doc.documentElement, compressHTML);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- function serialize(node) {
|
|
|
+ function serialize(node, compressHTML) {
|
|
|
if (node.nodeType == Node_TEXT_NODE) {
|
|
|
return serializeTextNode(node);
|
|
|
} else if (node.nodeType == Node_COMMENT_NODE) {
|
|
|
return serializeCommentNode(node);
|
|
|
} else if (node.nodeType == Node_ELEMENT_NODE) {
|
|
|
- return serializeElement(node);
|
|
|
+ return serializeElement(node, compressHTML);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -107,24 +107,24 @@ this.singlefile.lib.modules.serializer = this.singlefile.lib.modules.serializer
|
|
|
return "<!--" + commentNode.textContent + "-->";
|
|
|
}
|
|
|
|
|
|
- function serializeElement(element) {
|
|
|
+ function serializeElement(element, compressHTML) {
|
|
|
const tagName = element.tagName.toLowerCase();
|
|
|
- const omittedStartTag = OMITTED_START_TAGS.find(omittedStartTag => tagName == omittedStartTag.tagName && omittedStartTag.accept(element));
|
|
|
+ const omittedStartTag = compressHTML && OMITTED_START_TAGS.find(omittedStartTag => tagName == omittedStartTag.tagName && omittedStartTag.accept(element));
|
|
|
let content = "";
|
|
|
if (!omittedStartTag || element.attributes.length) {
|
|
|
content = "<" + tagName;
|
|
|
- Array.from(element.attributes, attribute => content += serializeAttribute(attribute, element));
|
|
|
+ Array.from(element.attributes, attribute => content += serializeAttribute(attribute, element, compressHTML));
|
|
|
content += ">";
|
|
|
}
|
|
|
Array.from(element.childNodes, childNode => content += serialize(childNode));
|
|
|
- const omittedEndTag = OMITTED_END_TAGS.find(omittedEndTag => tagName == omittedEndTag.tagName && omittedEndTag.accept(element.nextSibling, element));
|
|
|
+ const omittedEndTag = compressHTML && OMITTED_END_TAGS.find(omittedEndTag => tagName == omittedEndTag.tagName && omittedEndTag.accept(element.nextSibling, element));
|
|
|
if (!omittedEndTag && !SELF_CLOSED_TAG_NAMES.includes(tagName)) {
|
|
|
content += "</" + tagName + ">";
|
|
|
}
|
|
|
return content;
|
|
|
}
|
|
|
|
|
|
- function serializeAttribute(attribute, element) {
|
|
|
+ function serializeAttribute(attribute, element, compressHTML) {
|
|
|
const name = attribute.name;
|
|
|
let content = "";
|
|
|
if (!name.match(/["'>/=]/)) {
|
|
|
@@ -135,13 +135,13 @@ this.singlefile.lib.modules.serializer = this.singlefile.lib.modules.serializer
|
|
|
let simpleQuotesValue;
|
|
|
value = value.replace(/&/g, "&").replace(/\u00a0/g, " ");
|
|
|
if (value.includes("\"")) {
|
|
|
- if (value.includes("'")) {
|
|
|
+ if (value.includes("'") || compressHTML) {
|
|
|
value = value.replace(/"/g, """);
|
|
|
} else {
|
|
|
simpleQuotesValue = true;
|
|
|
}
|
|
|
}
|
|
|
- const invalidUnquotedValue = !value.match(/^[^ \t\n\f\r'"`=<>]+$/);
|
|
|
+ const invalidUnquotedValue = !compressHTML || !value.match(/^[^ \t\n\f\r'"`=<>]+$/);
|
|
|
content += " ";
|
|
|
if (!attribute.namespace) {
|
|
|
content += name;
|