q9
This commit is contained in:
25
node_modules/w3c-xmlserializer/LICENSE.md
generated
vendored
Normal file
25
node_modules/w3c-xmlserializer/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
The MIT License (MIT)
|
||||
=====================
|
||||
|
||||
Copyright © Sebastian Mayr
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the “Software”), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
41
node_modules/w3c-xmlserializer/README.md
generated
vendored
Normal file
41
node_modules/w3c-xmlserializer/README.md
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# w3c-xmlserializer
|
||||
|
||||
An XML serializer that follows the [W3C specification](https://w3c.github.io/DOM-Parsing/).
|
||||
|
||||
This package can be used in Node.js, as long as you feed it a DOM node, e.g. one produced by [jsdom](https://github.com/jsdom/jsdom).
|
||||
|
||||
## Basic usage
|
||||
|
||||
Assume you have a DOM tree rooted at a node `node`. In Node.js, you could create this using [jsdom](https://github.com/jsdom/jsdom) as follows:
|
||||
|
||||
```js
|
||||
const { JSDOM } = require("jsdom");
|
||||
|
||||
const { document } = new JSDOM().window;
|
||||
const node = document.createElement("akomaNtoso");
|
||||
```
|
||||
|
||||
Then, you use this package as follows:
|
||||
|
||||
|
||||
```js
|
||||
const serialize = require("w3c-xmlserializer");
|
||||
|
||||
console.log(serialize(node));
|
||||
// => '<akomantoso xmlns="http://www.w3.org/1999/xhtml"></akomantoso>'
|
||||
```
|
||||
|
||||
## `requireWellFormed` option
|
||||
|
||||
By default the input DOM tree is not required to be "well-formed"; any given input will serialize to some output string. You can instead require well-formedness via
|
||||
|
||||
```js
|
||||
serialize(node, { requireWellFormed: true });
|
||||
```
|
||||
|
||||
which will cause `Error`s to be thrown when non-well-formed constructs are encountered. [Per the spec](https://w3c.github.io/DOM-Parsing/#dfn-require-well-formed), this largely is about imposing constraints on the names of elements, attributes, etc.
|
||||
|
||||
As a point of reference, on the web platform:
|
||||
|
||||
* The [`innerHTML` getter](https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml) uses the require-well-formed mode, i.e. trying to get the `innerHTML` of non-well-formed subtrees will throw.
|
||||
* The [`xhr.send()` method](https://xhr.spec.whatwg.org/#the-send()-method) does not require well-formedness, i.e. sending non-well-formed `Document`s will serialize and send them anyway.
|
||||
125
node_modules/w3c-xmlserializer/lib/attributes.js
generated
vendored
Normal file
125
node_modules/w3c-xmlserializer/lib/attributes.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
"use strict";
|
||||
|
||||
const xnv = require("xml-name-validator");
|
||||
|
||||
const { NAMESPACES } = require("./constants");
|
||||
|
||||
function generatePrefix(map, newNamespace, prefixIndex) {
|
||||
const generatedPrefix = `ns${prefixIndex}`;
|
||||
map[newNamespace] = [generatedPrefix];
|
||||
return generatedPrefix;
|
||||
}
|
||||
|
||||
function preferredPrefixString(map, ns, preferredPrefix) {
|
||||
const candidateList = map[ns];
|
||||
if (!candidateList) {
|
||||
return null;
|
||||
}
|
||||
if (candidateList.includes(preferredPrefix)) {
|
||||
return preferredPrefix;
|
||||
}
|
||||
return candidateList[candidateList.length - 1];
|
||||
}
|
||||
|
||||
function serializeAttributeValue(value/* , requireWellFormed*/) {
|
||||
if (value === null) {
|
||||
return "";
|
||||
}
|
||||
// TODO: Check well-formedness
|
||||
return value
|
||||
.replace(/&/ug, "&")
|
||||
.replace(/"/ug, """)
|
||||
.replace(/</ug, "<")
|
||||
.replace(/>/ug, ">")
|
||||
.replace(/\t/ug, "	")
|
||||
.replace(/\n/ug, "
")
|
||||
.replace(/\r/ug, "
");
|
||||
}
|
||||
|
||||
function serializeAttributes(
|
||||
element,
|
||||
map,
|
||||
localPrefixes,
|
||||
ignoreNamespaceDefAttr,
|
||||
requireWellFormed,
|
||||
refs
|
||||
) {
|
||||
let result = "";
|
||||
const namespaceLocalnames = Object.create(null);
|
||||
for (const attr of element.attributes) {
|
||||
if (
|
||||
requireWellFormed &&
|
||||
namespaceLocalnames[attr.namespaceURI] &&
|
||||
namespaceLocalnames[attr.namespaceURI].has(attr.localName)
|
||||
) {
|
||||
throw new Error("Found duplicated attribute");
|
||||
}
|
||||
if (!namespaceLocalnames[attr.namespaceURI]) {
|
||||
namespaceLocalnames[attr.namespaceURI] = new Set();
|
||||
}
|
||||
namespaceLocalnames[attr.namespaceURI].add(attr.localName);
|
||||
const attributeNamespace = attr.namespaceURI;
|
||||
let candidatePrefix = null;
|
||||
if (attributeNamespace !== null) {
|
||||
candidatePrefix = preferredPrefixString(
|
||||
map,
|
||||
attributeNamespace,
|
||||
attr.prefix
|
||||
);
|
||||
if (attributeNamespace === NAMESPACES.XMLNS) {
|
||||
if (
|
||||
attr.value === NAMESPACES.XML ||
|
||||
(attr.prefix === null && ignoreNamespaceDefAttr) ||
|
||||
(attr.prefix !== null &&
|
||||
localPrefixes[attr.localName] !== attr.value &&
|
||||
map[attr.value].includes(attr.localName))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (requireWellFormed && attr.value === NAMESPACES.XMLNS) {
|
||||
throw new Error(
|
||||
"The XMLNS namespace is reserved and cannot be applied as an element's namespace via XML parsing"
|
||||
);
|
||||
}
|
||||
if (requireWellFormed && attr.value === "") {
|
||||
throw new Error(
|
||||
"Namespace prefix declarations cannot be used to undeclare a namespace"
|
||||
);
|
||||
}
|
||||
if (attr.prefix === "xmlns") {
|
||||
candidatePrefix = "xmlns";
|
||||
}
|
||||
} else if (candidatePrefix === null) {
|
||||
candidatePrefix = generatePrefix(
|
||||
map,
|
||||
attributeNamespace,
|
||||
refs.prefixIndex++
|
||||
);
|
||||
result += ` xmlns:${candidatePrefix}="${serializeAttributeValue(
|
||||
attributeNamespace,
|
||||
requireWellFormed
|
||||
)}"`;
|
||||
}
|
||||
}
|
||||
|
||||
result += " ";
|
||||
if (candidatePrefix !== null) {
|
||||
result += `${candidatePrefix}:`;
|
||||
}
|
||||
if (
|
||||
requireWellFormed &&
|
||||
(attr.localName.includes(":") ||
|
||||
!xnv.name(attr.localName) ||
|
||||
(attr.localName === "xmlns" && attributeNamespace === null))
|
||||
) {
|
||||
throw new Error("Invalid attribute localName value");
|
||||
}
|
||||
result += `${attr.localName}="${serializeAttributeValue(attr.value, requireWellFormed)}"`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports.preferredPrefixString = preferredPrefixString;
|
||||
module.exports.generatePrefix = generatePrefix;
|
||||
module.exports.serializeAttributeValue = serializeAttributeValue;
|
||||
module.exports.serializeAttributes = serializeAttributes;
|
||||
44
node_modules/w3c-xmlserializer/lib/constants.js
generated
vendored
Normal file
44
node_modules/w3c-xmlserializer/lib/constants.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
|
||||
module.exports.NAMESPACES = {
|
||||
HTML: "http://www.w3.org/1999/xhtml",
|
||||
XML: "http://www.w3.org/XML/1998/namespace",
|
||||
XMLNS: "http://www.w3.org/2000/xmlns/"
|
||||
};
|
||||
|
||||
module.exports.NODE_TYPES = {
|
||||
ELEMENT_NODE: 1,
|
||||
ATTRIBUTE_NODE: 2, // historical
|
||||
TEXT_NODE: 3,
|
||||
CDATA_SECTION_NODE: 4,
|
||||
ENTITY_REFERENCE_NODE: 5, // historical
|
||||
ENTITY_NODE: 6, // historical
|
||||
PROCESSING_INSTRUCTION_NODE: 7,
|
||||
COMMENT_NODE: 8,
|
||||
DOCUMENT_NODE: 9,
|
||||
DOCUMENT_TYPE_NODE: 10,
|
||||
DOCUMENT_FRAGMENT_NODE: 11,
|
||||
NOTATION_NODE: 12 // historical
|
||||
};
|
||||
|
||||
module.exports.VOID_ELEMENTS = new Set([
|
||||
"area",
|
||||
"base",
|
||||
"basefont",
|
||||
"bgsound",
|
||||
"br",
|
||||
"col",
|
||||
"embed",
|
||||
"frame",
|
||||
"hr",
|
||||
"img",
|
||||
"input",
|
||||
"keygen",
|
||||
"link",
|
||||
"menuitem",
|
||||
"meta",
|
||||
"param",
|
||||
"source",
|
||||
"track",
|
||||
"wbr"
|
||||
]);
|
||||
365
node_modules/w3c-xmlserializer/lib/serialize.js
generated
vendored
Normal file
365
node_modules/w3c-xmlserializer/lib/serialize.js
generated
vendored
Normal file
@@ -0,0 +1,365 @@
|
||||
"use strict";
|
||||
|
||||
const xnv = require("xml-name-validator");
|
||||
|
||||
const attributeUtils = require("./attributes");
|
||||
const { NAMESPACES, VOID_ELEMENTS, NODE_TYPES } = require("./constants");
|
||||
|
||||
const XML_CHAR = /^(\x09|\x0A|\x0D|[\x20-\uD7FF]|[\uE000-\uFFFD]|[\u{10000}-\u{10FFFF}])*$/u;
|
||||
const PUBID_CHAR = /^(\x20|\x0D|\x0A|[a-zA-Z0-9]|[-'()+,./:=?;!*#@$_%])*$/u;
|
||||
|
||||
function asciiCaseInsensitiveMatch(a, b) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if ((a.charCodeAt(i) | 32) !== (b.charCodeAt(i) | 32)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function recordNamespaceInformation(element, map, prefixMap) {
|
||||
let defaultNamespaceAttrValue = null;
|
||||
for (let i = 0; i < element.attributes.length; ++i) {
|
||||
const attr = element.attributes[i];
|
||||
if (attr.namespaceURI === NAMESPACES.XMLNS) {
|
||||
if (attr.prefix === null) {
|
||||
defaultNamespaceAttrValue = attr.value;
|
||||
continue;
|
||||
}
|
||||
let namespaceDefinition = attr.value;
|
||||
if (namespaceDefinition === NAMESPACES.XML) {
|
||||
continue;
|
||||
}
|
||||
// This is exactly the other way than the spec says, but that's intended.
|
||||
// All the maps coalesce null to the empty string (explained in the
|
||||
// spec), so instead of doing that every time, just do it once here.
|
||||
if (namespaceDefinition === null) {
|
||||
namespaceDefinition = "";
|
||||
}
|
||||
|
||||
if (
|
||||
namespaceDefinition in map &&
|
||||
map[namespaceDefinition].includes(attr.localName)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (!(namespaceDefinition in map)) {
|
||||
map[namespaceDefinition] = [];
|
||||
}
|
||||
map[namespaceDefinition].push(attr.localName);
|
||||
prefixMap[attr.localName] = namespaceDefinition;
|
||||
}
|
||||
}
|
||||
return defaultNamespaceAttrValue;
|
||||
}
|
||||
|
||||
function serializeDocumentType(node, namespace, prefixMap, requireWellFormed) {
|
||||
if (requireWellFormed && !PUBID_CHAR.test(node.publicId)) {
|
||||
throw new Error("Failed to serialize XML: document type node publicId is not well-formed.");
|
||||
}
|
||||
|
||||
if (
|
||||
requireWellFormed &&
|
||||
(!XML_CHAR.test(node.systemId) ||
|
||||
(node.systemId.includes('"') && node.systemId.includes("'")))
|
||||
) {
|
||||
throw new Error("Failed to serialize XML: document type node systemId is not well-formed.");
|
||||
}
|
||||
|
||||
let markup = `<!DOCTYPE ${node.name}`;
|
||||
if (node.publicId !== "") {
|
||||
markup += ` PUBLIC "${node.publicId}"`;
|
||||
} else if (node.systemId !== "") {
|
||||
markup += " SYSTEM";
|
||||
}
|
||||
if (node.systemId !== "") {
|
||||
markup += ` "${node.systemId}"`;
|
||||
}
|
||||
return `${markup}>`;
|
||||
}
|
||||
|
||||
function serializeProcessingInstruction(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed
|
||||
) {
|
||||
if (
|
||||
requireWellFormed &&
|
||||
(node.target.includes(":") || asciiCaseInsensitiveMatch(node.target, "xml"))
|
||||
) {
|
||||
throw new Error("Failed to serialize XML: processing instruction node target is not well-formed.");
|
||||
}
|
||||
if (
|
||||
requireWellFormed &&
|
||||
(!XML_CHAR.test(node.data) || node.data.includes("?>"))
|
||||
) {
|
||||
throw new Error("Failed to serialize XML: processing instruction node data is not well-formed.");
|
||||
}
|
||||
return `<?${node.target} ${node.data}?>`;
|
||||
}
|
||||
|
||||
function serializeDocument(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed,
|
||||
refs
|
||||
) {
|
||||
if (requireWellFormed && node.documentElement === null) {
|
||||
throw new Error("Failed to serialize XML: document does not have a document element.");
|
||||
}
|
||||
let serializedDocument = "";
|
||||
for (const child of node.childNodes) {
|
||||
serializedDocument += xmlSerialization(
|
||||
child,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
}
|
||||
return serializedDocument;
|
||||
}
|
||||
|
||||
function serializeDocumentFragment(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed,
|
||||
refs
|
||||
) {
|
||||
let markup = "";
|
||||
for (const child of node.childNodes) {
|
||||
markup += xmlSerialization(
|
||||
child,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
}
|
||||
return markup;
|
||||
}
|
||||
|
||||
function serializeText(node, namespace, prefixMap, requireWellFormed) {
|
||||
if (requireWellFormed && !XML_CHAR.test(node.data)) {
|
||||
throw new Error("Failed to serialize XML: text node data is not well-formed.");
|
||||
}
|
||||
|
||||
return node.data
|
||||
.replace(/&/ug, "&")
|
||||
.replace(/</ug, "<")
|
||||
.replace(/>/ug, ">");
|
||||
}
|
||||
|
||||
function serializeComment(node, namespace, prefixMap, requireWellFormed) {
|
||||
if (requireWellFormed && !XML_CHAR.test(node.data)) {
|
||||
throw new Error("Failed to serialize XML: comment node data is not well-formed.");
|
||||
}
|
||||
|
||||
if (
|
||||
requireWellFormed &&
|
||||
(node.data.includes("--") || node.data.endsWith("-"))
|
||||
) {
|
||||
throw new Error("Failed to serialize XML: found hyphens in illegal places in comment node data.");
|
||||
}
|
||||
return `<!--${node.data}-->`;
|
||||
}
|
||||
|
||||
function serializeElement(node, namespace, prefixMap, requireWellFormed, refs) {
|
||||
if (
|
||||
requireWellFormed &&
|
||||
(node.localName.includes(":") || !xnv.name(node.localName))
|
||||
) {
|
||||
throw new Error("Failed to serialize XML: element node localName is not a valid XML name.");
|
||||
}
|
||||
let markup = "<";
|
||||
let qualifiedName = "";
|
||||
let skipEndTag = false;
|
||||
let ignoreNamespaceDefinitionAttr = false;
|
||||
const map = { ...prefixMap };
|
||||
const localPrefixesMap = Object.create(null);
|
||||
const localDefaultNamespace = recordNamespaceInformation(
|
||||
node,
|
||||
map,
|
||||
localPrefixesMap
|
||||
);
|
||||
let inheritedNs = namespace;
|
||||
const ns = node.namespaceURI;
|
||||
if (inheritedNs === ns) {
|
||||
if (localDefaultNamespace !== null) {
|
||||
ignoreNamespaceDefinitionAttr = true;
|
||||
}
|
||||
if (ns === NAMESPACES.XML) {
|
||||
qualifiedName = `xml:${node.localName}`;
|
||||
} else {
|
||||
qualifiedName = node.localName;
|
||||
}
|
||||
markup += qualifiedName;
|
||||
} else {
|
||||
let { prefix } = node;
|
||||
let candidatePrefix = attributeUtils.preferredPrefixString(map, ns, prefix);
|
||||
if (prefix === "xmlns") {
|
||||
if (requireWellFormed) {
|
||||
throw new Error("Failed to serialize XML: element nodes can't have a prefix of \"xmlns\".");
|
||||
}
|
||||
candidatePrefix = "xmlns";
|
||||
}
|
||||
if (candidatePrefix !== null) {
|
||||
qualifiedName = `${candidatePrefix}:${node.localName}`;
|
||||
if (
|
||||
localDefaultNamespace !== null &&
|
||||
localDefaultNamespace !== NAMESPACES.XML
|
||||
) {
|
||||
inheritedNs =
|
||||
localDefaultNamespace === "" ? null : localDefaultNamespace;
|
||||
}
|
||||
markup += qualifiedName;
|
||||
} else if (prefix !== null) {
|
||||
if (prefix in localPrefixesMap) {
|
||||
prefix = attributeUtils.generatePrefix(map, ns, refs.prefixIndex++);
|
||||
}
|
||||
if (map[ns]) {
|
||||
map[ns].push(prefix);
|
||||
} else {
|
||||
map[ns] = [prefix];
|
||||
}
|
||||
qualifiedName = `${prefix}:${node.localName}`;
|
||||
markup += `${qualifiedName} xmlns:${prefix}="${attributeUtils.serializeAttributeValue(ns, requireWellFormed)}"`;
|
||||
if (localDefaultNamespace !== null) {
|
||||
inheritedNs =
|
||||
localDefaultNamespace === "" ? null : localDefaultNamespace;
|
||||
}
|
||||
} else if (localDefaultNamespace === null || localDefaultNamespace !== ns) {
|
||||
ignoreNamespaceDefinitionAttr = true;
|
||||
qualifiedName = node.localName;
|
||||
inheritedNs = ns;
|
||||
markup += `${qualifiedName} xmlns="${attributeUtils.serializeAttributeValue(ns, requireWellFormed)}"`;
|
||||
} else {
|
||||
qualifiedName = node.localName;
|
||||
inheritedNs = ns;
|
||||
markup += qualifiedName;
|
||||
}
|
||||
}
|
||||
|
||||
markup += attributeUtils.serializeAttributes(
|
||||
node,
|
||||
map,
|
||||
localPrefixesMap,
|
||||
ignoreNamespaceDefinitionAttr,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
|
||||
if (
|
||||
ns === NAMESPACES.HTML &&
|
||||
node.childNodes.length === 0 &&
|
||||
VOID_ELEMENTS.has(node.localName)
|
||||
) {
|
||||
markup += " /";
|
||||
skipEndTag = true;
|
||||
} else if (ns !== NAMESPACES.HTML && node.childNodes.length === 0) {
|
||||
markup += "/";
|
||||
skipEndTag = true;
|
||||
}
|
||||
markup += ">";
|
||||
if (skipEndTag) {
|
||||
return markup;
|
||||
}
|
||||
|
||||
if (ns === NAMESPACES.HTML && node.localName === "template") {
|
||||
markup += xmlSerialization(
|
||||
node.content,
|
||||
inheritedNs,
|
||||
map,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
} else {
|
||||
for (const child of node.childNodes) {
|
||||
markup += xmlSerialization(
|
||||
child,
|
||||
inheritedNs,
|
||||
map,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
}
|
||||
}
|
||||
markup += `</${qualifiedName}>`;
|
||||
return markup;
|
||||
}
|
||||
|
||||
function serializeCDATASection(node) {
|
||||
return `<![CDATA[${node.data}]]>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{prefixIndex: number}} refs
|
||||
*/
|
||||
function xmlSerialization(node, namespace, prefixMap, requireWellFormed, refs) {
|
||||
switch (node.nodeType) {
|
||||
case NODE_TYPES.ELEMENT_NODE:
|
||||
return serializeElement(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
case NODE_TYPES.DOCUMENT_NODE:
|
||||
return serializeDocument(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
case NODE_TYPES.COMMENT_NODE:
|
||||
return serializeComment(node, namespace, prefixMap, requireWellFormed);
|
||||
case NODE_TYPES.TEXT_NODE:
|
||||
return serializeText(node, namespace, prefixMap, requireWellFormed);
|
||||
case NODE_TYPES.DOCUMENT_FRAGMENT_NODE:
|
||||
return serializeDocumentFragment(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed,
|
||||
refs
|
||||
);
|
||||
case NODE_TYPES.DOCUMENT_TYPE_NODE:
|
||||
return serializeDocumentType(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed
|
||||
);
|
||||
case NODE_TYPES.PROCESSING_INSTRUCTION_NODE:
|
||||
return serializeProcessingInstruction(
|
||||
node,
|
||||
namespace,
|
||||
prefixMap,
|
||||
requireWellFormed
|
||||
);
|
||||
case NODE_TYPES.ATTRIBUTE_NODE:
|
||||
return "";
|
||||
case NODE_TYPES.CDATA_SECTION_NODE:
|
||||
return serializeCDATASection(node);
|
||||
default:
|
||||
throw new TypeError("Failed to serialize XML: only Nodes can be serialized.");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = (root, { requireWellFormed = false } = {}) => {
|
||||
const namespacePrefixMap = Object.create(null);
|
||||
namespacePrefixMap["http://www.w3.org/XML/1998/namespace"] = ["xml"];
|
||||
return xmlSerialization(root, null, namespacePrefixMap, requireWellFormed, {
|
||||
prefixIndex: 1
|
||||
});
|
||||
};
|
||||
176
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/LICENSE.txt
generated
vendored
Normal file
176
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
35
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/README.md
generated
vendored
Normal file
35
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/README.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Validate XML Names and Qualified Names
|
||||
|
||||
This package simply tells you whether or not a string matches the [`Name`](http://www.w3.org/TR/xml/#NT-Name) or [`QName`](http://www.w3.org/TR/xml-names/#NT-QName) productions in the XML Namespaces specification. We use it for implementing the [validate](https://dom.spec.whatwg.org/#validate) algorithm in jsdom, but you can use it for whatever you want.
|
||||
|
||||
## Usage
|
||||
|
||||
This package's main module exports two functions, `name()` and `qname()`. Both take a string and return a boolean indicating whether or not the string matches the relevant production.
|
||||
|
||||
```js
|
||||
"use strict":
|
||||
const xnv = require("xml-name-validator");
|
||||
|
||||
// Will return true
|
||||
xnv.name("x");
|
||||
xnv.name(":");
|
||||
xnv.name("a:0");
|
||||
xnv.name("a:b:c");
|
||||
|
||||
// Will return false
|
||||
xnv.name("\\");
|
||||
xnv.name("'");
|
||||
xnv.name("0");
|
||||
xnv.name("a!");
|
||||
|
||||
// Will return true
|
||||
xnv.qname("x");
|
||||
xnv.qname("a0");
|
||||
xnv.qname("a:b");
|
||||
|
||||
// Will return false
|
||||
xnv.qname(":a");
|
||||
xnv.qname(":b");
|
||||
xnv.qname("a:b:c");
|
||||
xnv.qname("a:0");
|
||||
```
|
||||
9
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/lib/xml-name-validator.js
generated
vendored
Normal file
9
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/lib/xml-name-validator.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
exports.name = potentialName => {
|
||||
return /^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/u.test(potentialName);
|
||||
};
|
||||
|
||||
exports.qname = potentialQname => {
|
||||
return /(?:^[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}][A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*:[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}][A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$)|(?:^[A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}][A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$)/u.test(potentialQname);
|
||||
};
|
||||
30
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/package.json
generated
vendored
Normal file
30
node_modules/w3c-xmlserializer/node_modules/xml-name-validator/package.json
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "xml-name-validator",
|
||||
"description": "Validates whether a string matches the production for an XML name or qualified name",
|
||||
"keywords": [
|
||||
"xml",
|
||||
"name",
|
||||
"qname"
|
||||
],
|
||||
"version": "5.0.0",
|
||||
"author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)",
|
||||
"license": "Apache-2.0",
|
||||
"repository": "jsdom/xml-name-validator",
|
||||
"main": "lib/xml-name-validator.js",
|
||||
"files": [
|
||||
"lib/"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "node --test",
|
||||
"benchmark": "node scripts/benchmark.js",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@domenic/eslint-config": "^3.0.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"eslint": "^8.53.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
}
|
||||
32
node_modules/w3c-xmlserializer/package.json
generated
vendored
Normal file
32
node_modules/w3c-xmlserializer/package.json
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "w3c-xmlserializer",
|
||||
"description": "A per-spec XML serializer implementation",
|
||||
"keywords": [
|
||||
"dom",
|
||||
"w3c",
|
||||
"xml",
|
||||
"xmlserializer"
|
||||
],
|
||||
"version": "5.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"xml-name-validator": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@domenic/eslint-config": "^3.0.0",
|
||||
"eslint": "^8.53.0",
|
||||
"jsdom": "^22.1.0"
|
||||
},
|
||||
"repository": "jsdom/w3c-xmlserializer",
|
||||
"files": [
|
||||
"lib/"
|
||||
],
|
||||
"main": "lib/serialize.js",
|
||||
"scripts": {
|
||||
"test": "node --test",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user