diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-10-17 19:10:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-17 19:10:44 +0200 |
commit | c423bdaf0364fe1dd3b540145779ccd0c6a053f7 (patch) | |
tree | addb412037fc321793a64a54dc2fbc4cd83751d7 /toolkit/components/reader/JSDOMParser.js | |
parent | 46eab94c094807ff590267872cf32a664625932f (diff) | |
parent | f696173b4af510cf72885282efcfdd3c4005fbb1 (diff) | |
download | UXP-c423bdaf0364fe1dd3b540145779ccd0c6a053f7.tar UXP-c423bdaf0364fe1dd3b540145779ccd0c6a053f7.tar.gz UXP-c423bdaf0364fe1dd3b540145779ccd0c6a053f7.tar.lz UXP-c423bdaf0364fe1dd3b540145779ccd0c6a053f7.tar.xz UXP-c423bdaf0364fe1dd3b540145779ccd0c6a053f7.zip |
Merge pull request #837 from Ascrod/readerview
Reader Updates
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; |