aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cheerio/lib/parse.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-02-09 17:58:07 +0100
committerMinteck <contact@minteck.org>2022-02-09 17:58:07 +0100
commit22a25ded9f7d9c9a96cce8d1bc12475ca0434201 (patch)
tree0e33d0650fe58f41c00bbc4b8047956905766823 /node_modules/cheerio/lib/parse.js
parent8f54d903fb3470823a5e4d6ff4655de009836245 (diff)
downloadyoutoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.gz
youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.bz2
youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.zip
Major update
Diffstat (limited to 'node_modules/cheerio/lib/parse.js')
-rw-r--r--node_modules/cheerio/lib/parse.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/node_modules/cheerio/lib/parse.js b/node_modules/cheerio/lib/parse.js
new file mode 100644
index 0000000..cd92fc9
--- /dev/null
+++ b/node_modules/cheerio/lib/parse.js
@@ -0,0 +1,67 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.update = void 0;
+var htmlparser2_1 = require("htmlparser2");
+var htmlparser2_adapter_1 = require("./parsers/htmlparser2-adapter");
+var parse5_adapter_1 = require("./parsers/parse5-adapter");
+var domhandler_1 = require("domhandler");
+/*
+ * Parser
+ */
+function parse(content, options, isDocument) {
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer(content)) {
+ content = content.toString();
+ }
+ if (typeof content === 'string') {
+ return options.xmlMode || options._useHtmlParser2
+ ? htmlparser2_adapter_1.parse(content, options)
+ : parse5_adapter_1.parse(content, options, isDocument);
+ }
+ var doc = content;
+ if (!Array.isArray(doc) && domhandler_1.isDocument(doc)) {
+ // If `doc` is already a root, just return it
+ return doc;
+ }
+ // Add conent to new root element
+ var root = new domhandler_1.Document([]);
+ // Update the DOM using the root
+ update(doc, root);
+ return root;
+}
+exports.default = parse;
+/**
+ * Update the dom structure, for one changed layer.
+ *
+ * @param newChilds - The new children.
+ * @param parent - The new parent.
+ * @returns The parent node.
+ */
+function update(newChilds, parent) {
+ // Normalize
+ var arr = Array.isArray(newChilds) ? newChilds : [newChilds];
+ // Update parent
+ if (parent) {
+ parent.children = arr;
+ }
+ else {
+ parent = null;
+ }
+ // Update neighbors
+ for (var i = 0; i < arr.length; i++) {
+ var node = arr[i];
+ // Cleanly remove existing nodes from their previous structures.
+ if (node.parent && node.parent.children !== arr) {
+ htmlparser2_1.DomUtils.removeElement(node);
+ }
+ if (parent) {
+ node.prev = arr[i - 1] || null;
+ node.next = arr[i + 1] || null;
+ }
+ else {
+ node.prev = node.next = null;
+ }
+ node.parent = parent;
+ }
+ return parent;
+}
+exports.update = update;