Parse note content in reports as HTML instead of XML
And remove raw-markup fallback when not XML
This commit is contained in:
parent
ae47ae28bd
commit
835003dd6d
1 changed files with 9 additions and 29 deletions
|
@ -27,6 +27,9 @@
|
|||
Zotero.Report = {};
|
||||
|
||||
Zotero.Report.HTML = new function () {
|
||||
let domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||
.createInstance(Components.interfaces.nsIDOMParser);
|
||||
|
||||
this.listGenerator = function* (items, combineChildItems) {
|
||||
yield '<!DOCTYPE html>\n'
|
||||
+ '<html>\n'
|
||||
|
@ -67,25 +70,13 @@ Zotero.Report.HTML = new function () {
|
|||
if (obj['note']) {
|
||||
content += '\n\t\t\t';
|
||||
|
||||
// If not valid XML, display notes with entities encoded
|
||||
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||
.createInstance(Components.interfaces.nsIDOMParser);
|
||||
var doc = parser.parseFromString('<div>'
|
||||
let doc = domParser.parseFromString('<div>'
|
||||
+ obj.note
|
||||
// isn't valid in HTML
|
||||
.replace(/ /g, " ")
|
||||
// Strip control characters (for notes that were
|
||||
// added before item.setNote() started doing this)
|
||||
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "")
|
||||
+ '</div>', "application/xml");
|
||||
if (doc.documentElement.tagName == 'parsererror') {
|
||||
Zotero.debug(doc.documentElement.textContent, 2);
|
||||
content += '<p class="plaintext">' + escapeXML(obj.note) + '</p>\n';
|
||||
}
|
||||
// Otherwise render markup normally
|
||||
else {
|
||||
content += obj.note + '\n';
|
||||
}
|
||||
+ '</div>', "text/html");
|
||||
content += doc.body.innerHTML + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,24 +92,13 @@ Zotero.Report.HTML = new function () {
|
|||
for (let note of obj.reportChildren.notes) {
|
||||
content += '\t\t\t\t\t<li id="item_' + note.key + '">\n';
|
||||
|
||||
// If not valid XML, display notes with entities encoded
|
||||
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||
.createInstance(Components.interfaces.nsIDOMParser);
|
||||
var doc = parser.parseFromString('<div>'
|
||||
let doc = domParser.parseFromString('<div>'
|
||||
+ note.note
|
||||
.replace(/ /g, " ")
|
||||
// Strip control characters (for notes that were
|
||||
// added before item.setNote() started doing this)
|
||||
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "")
|
||||
+ '</div>', "application/xml");
|
||||
if (doc.documentElement.tagName == 'parsererror') {
|
||||
Zotero.debug(doc.documentElement.textContent, 2);
|
||||
content += '<p class="plaintext">' + escapeXML(note.note) + '</p>\n';
|
||||
}
|
||||
// Otherwise render markup normally
|
||||
else {
|
||||
content += note.note + '\n';
|
||||
}
|
||||
+ '</div>', "text/html");
|
||||
content += doc.body.innerHTML + '\n';
|
||||
|
||||
// Child note tags
|
||||
content += _generateTagsList(note);
|
||||
|
|
Loading…
Reference in a new issue