Convert feed processor parsing to native DOM APIs
This uses native DOM APIs to create document fragments and parse content instead of XPCOM utils.
This commit is contained in:
parent
b4303eaa45
commit
891ba599a6
1 changed files with 10 additions and 15 deletions
|
@ -11,7 +11,6 @@ function LOG(str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const SAX_CONTRACTID = "@mozilla.org/saxparser/xmlreader;1";
|
const SAX_CONTRACTID = "@mozilla.org/saxparser/xmlreader;1";
|
||||||
const PARSERUTILS_CONTRACTID = "@mozilla.org/parserutils;1";
|
|
||||||
|
|
||||||
const XMLNS = "http://www.w3.org/XML/1998/namespace";
|
const XMLNS = "http://www.w3.org/XML/1998/namespace";
|
||||||
const RSS090NS = "http://my.netscape.com/rdf/simple/0.9/";
|
const RSS090NS = "http://my.netscape.com/rdf/simple/0.9/";
|
||||||
|
@ -567,42 +566,38 @@ function TextConstruct() {
|
||||||
this.base = null;
|
this.base = null;
|
||||||
this.type = "text";
|
this.type = "text";
|
||||||
this.text = null;
|
this.text = null;
|
||||||
this.parserUtils = Cc[PARSERUTILS_CONTRACTID].getService(Ci.nsIParserUtils);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextConstruct.prototype = {
|
TextConstruct.prototype = {
|
||||||
plainText: function () {
|
plainText: function () {
|
||||||
if (this.type != "text") {
|
if (this.type != "text") {
|
||||||
return this.parserUtils.convertToPlainText(stripTags(this.text),
|
return stripTags(this.text);
|
||||||
Ci.nsIDocumentEncoder.OutputSelectionOnly
|
|
||||||
| Ci.nsIDocumentEncoder.OutputAbsoluteLinks,
|
|
||||||
0);
|
|
||||||
}
|
}
|
||||||
return this.text;
|
return this.text;
|
||||||
},
|
},
|
||||||
|
|
||||||
createDocumentFragment: function (element) {
|
createDocumentFragment: function (element) {
|
||||||
if (this.type == "text") {
|
if (this.type == "text") {
|
||||||
var doc = element.ownerDocument;
|
const doc = element.ownerDocument;
|
||||||
var docFragment = doc.createDocumentFragment();
|
const docFragment = doc.createDocumentFragment();
|
||||||
var node = doc.createTextNode(this.text);
|
const node = doc.createTextNode(this.text);
|
||||||
docFragment.appendChild(node);
|
docFragment.appendChild(node);
|
||||||
return docFragment;
|
return docFragment;
|
||||||
}
|
}
|
||||||
var isXML;
|
|
||||||
|
let parserType;
|
||||||
if (this.type == "xhtml") {
|
if (this.type == "xhtml") {
|
||||||
isXML = true;
|
parserType = "application/xhtml+xml";
|
||||||
}
|
}
|
||||||
else if (this.type == "html") {
|
else if (this.type == "html") {
|
||||||
isXML = false;
|
parserType = "text/html";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let flags = Ci.nsIParserUtils.SanitizerDropForms;
|
const parsedDoc = new DOMParser().parseFromString(this.text, parserType);
|
||||||
return this.parserUtils.parseFragment(this.text, flags, isXML,
|
return parsedDoc.documentElement;
|
||||||
this.base, element);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue