|
|
@@ -85,26 +85,27 @@ this.serializer = this.serializer || (() => {
|
|
|
const tagName = element.tagName.toLowerCase();
|
|
|
let content = "<" + tagName;
|
|
|
Array.from(element.attributes).forEach(attribute => {
|
|
|
+ const name = attribute.name.replace(/["'>/=]/g, "");
|
|
|
let value = attribute.value;
|
|
|
- if (attribute.name == "class") {
|
|
|
+ if (name == "class") {
|
|
|
value = Array.from(element.classList).map(className => className.trim()).join(" ");
|
|
|
}
|
|
|
value = value.replace(/&/g, "&").replace(/\u00a0/g, " ").replace(/"/g, """);
|
|
|
const validUnquotedValue = value.match(/^[^ \t\n\f\r"'`=<>]+$/);
|
|
|
content += " ";
|
|
|
if (!attribute.namespace) {
|
|
|
- content += attribute.name;
|
|
|
+ content += name;
|
|
|
} else if (attribute.namespaceURI == "http://www.w3.org/XML/1998/namespace") {
|
|
|
- content += "xml:" + attribute.name;
|
|
|
+ content += "xml:" + name;
|
|
|
} else if (attribute.namespaceURI == "http://www.w3.org/2000/xmlns/") {
|
|
|
- if (attribute.name !== "xmlns") {
|
|
|
+ if (name !== "xmlns") {
|
|
|
content += "xmlns:";
|
|
|
}
|
|
|
- content += attribute.name;
|
|
|
+ content += name;
|
|
|
} else if (attribute.namespaceURI == "http://www.w3.org/1999/xlink") {
|
|
|
- content += "xlink:" + attribute.name;
|
|
|
+ content += "xlink:" + name;
|
|
|
} else {
|
|
|
- content += attribute.name;
|
|
|
+ content += name;
|
|
|
}
|
|
|
if (value != "") {
|
|
|
content += "=";
|
|
|
@@ -121,7 +122,7 @@ this.serializer = this.serializer || (() => {
|
|
|
Array.from(element.childNodes).forEach(childNode => content += serialize(childNode));
|
|
|
const omittedEndTag = OMITTED_END_TAGS.find(omittedEndTag => {
|
|
|
const nextSibling = element.nextSibling;
|
|
|
- return tagName == omittedEndTag.tagName && (!nextSibling || (nextSibling.nodeType == Node.ELEMENT_NODE && omittedEndTag.followings && omittedEndTag.followings.includes(nextSibling.tagName)));
|
|
|
+ return tagName == omittedEndTag.tagName && (!nextSibling || (nextSibling.nodeType == Node.ELEMENT_NODE && omittedEndTag.followings && omittedEndTag.followings.includes(nextSibling.tagName.toLowerCase())));
|
|
|
});
|
|
|
if (!omittedEndTag && !SELF_CLOSED_TAG_NAMES.includes(tagName)) {
|
|
|
content += "</" + tagName + ">";
|