diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-10-19 09:16:25 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-10-19 09:16:25 +0200 |
commit | 56eb74dbedb8663070f837deee42d31d027e3dd7 (patch) | |
tree | 94c5bbbb4cd7dabc9561dfd44de8d7d347c080b8 /toolkit/components/reader/JSDOMParser.js | |
parent | 8c3d0aaca0d1db89a3a23665cfde43980c6191ed (diff) | |
parent | c423bdaf0364fe1dd3b540145779ccd0c6a053f7 (diff) | |
download | UXP-56eb74dbedb8663070f837deee42d31d027e3dd7.tar UXP-56eb74dbedb8663070f837deee42d31d027e3dd7.tar.gz UXP-56eb74dbedb8663070f837deee42d31d027e3dd7.tar.lz UXP-56eb74dbedb8663070f837deee42d31d027e3dd7.tar.xz UXP-56eb74dbedb8663070f837deee42d31d027e3dd7.zip |
Merge branch 'master' of https://github.com/MoonchildProductions/UXP
Diffstat (limited to 'toolkit/components/reader/JSDOMParser.js')
-rw-r--r-- | toolkit/components/reader/JSDOMParser.js | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/toolkit/components/reader/JSDOMParser.js b/toolkit/components/reader/JSDOMParser.js index dd9d37230..debdb08eb 100644 --- a/toolkit/components/reader/JSDOMParser.js +++ b/toolkit/components/reader/JSDOMParser.js @@ -618,6 +618,13 @@ }; var Element = function (tag) { + // We use this to find the closing tag. + this._matchingTag = tag; + // We're explicitly a non-namespace aware parser, we just pretend it's all HTML. + var lastColonIndex = tag.lastIndexOf(":"); + if (lastColonIndex != -1) { + tag = tag.substring(lastColonIndex + 1); + } this.attributes = []; this.childNodes = []; this.children = []; @@ -785,7 +792,13 @@ break; } } - } + }, + + hasAttribute: function (name) { + return this.attributes.some(function (attr) { + return attr.name == name; + }); + }, }; var Style = function (node) { @@ -1062,9 +1075,10 @@ return null; // Read any text as Text node + var textNode; if (c !== "<") { --this.currentChar; - var textNode = new Text(); + textNode = new Text(); var n = this.html.indexOf("<", this.currentChar); if (n === -1) { textNode.innerHTML = this.html.substring(this.currentChar, this.html.length); @@ -1076,6 +1090,18 @@ return textNode; } + if (this.match("![CDATA[")) { + var endChar = this.html.indexOf("]]>", this.currentChar); + if (endChar === -1) { + this.error("unclosed CDATA section"); + return null; + } + textNode = new Text(); + textNode.textContent = this.html.substring(this.currentChar, endChar); + this.currentChar = endChar + ("]]>").length; + return textNode; + } + c = this.peekNext(); // Read Comment node. Normally, Comment nodes know their inner @@ -1107,7 +1133,7 @@ // If this isn't a void Element, read its child nodes if (!closed) { this.readChildren(node); - var closingTag = "</" + localName + ">"; + var closingTag = "</" + node._matchingTag + ">"; if (!this.match(closingTag)) { this.error("expected '" + closingTag + "' and got " + this.html.substr(this.currentChar, closingTag.length)); return null; |