commit 21bf3000cbe64ad5345bb731b0e8396aa004b13f
parent aa0a3544bde6a056dc4fb8214d3eb812d2544aff
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 31 Oct 2012 04:38:45 -0400
Better method for determining valid XHTML notes in reports
Previously looked for <p> tag. Now just check if it's valid XML.
Diffstat:
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/chrome/content/zotero/xpcom/report.js b/chrome/content/zotero/xpcom/report.js
@@ -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,12 +103,16 @@ 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';
+ // 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';
}
- // Wrap plaintext notes in <p>
+ // Otherwise render markup normally
else {
- content += '<p class="plaintext">' + escapeXML(note.note) + '</p>\n';
+ content += note.note + '\n';
}
// Child note tags