Better method for determining valid XHTML notes in reports

Previously looked for <p> tag. Now just check if it's valid XML.
This commit is contained in:
Dan Stillman 2012-10-31 04:38:45 -04:00
parent aa0a3544bd
commit 21bf3000cb

View file

@ -76,12 +76,17 @@ Zotero.Report = new function() {
// Independent note
if (arr['note']) {
content += '\n';
if (arr.note.substr(0, 1024).match(/<p[^>]*>/)) {
content += arr.note + '\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(arr.note, "application/xml");
if (doc.documentElement.tagName == 'parsererror') {
content += '<p class="plaintext">' + escapeXML(arr.note) + '</p>\n';
}
// Wrap plaintext notes in <p>
// Otherwise render markup normally
else {
content += '<p class="plaintext">' + arr.note + '</p>\n';
content += arr.note + '\n';
}
}
}
@ -98,13 +103,17 @@ Zotero.Report = new function() {
for each(var note in arr.reportChildren.notes) {
content += '<li id="i' + note.itemID + '">\n';
if (note.note.substr(0, 1024).match(/<p[^>]*>/)) {
content += note.note + '\n';
}
// Wrap plaintext notes in <p>
else {
// 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(note.note, "application/xml");
if (doc.documentElement.tagName == 'parsererror') {
content += '<p class="plaintext">' + escapeXML(note.note) + '</p>\n';
}
// Otherwise render markup normally
else {
content += note.note + '\n';
}
// Child note tags
content += _generateTagsList(note);