From 21bf3000cbe64ad5345bb731b0e8396aa004b13f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 31 Oct 2012 04:38:45 -0400 Subject: [PATCH] Better method for determining valid XHTML notes in reports Previously looked for

tag. Now just check if it's valid XML. --- chrome/content/zotero/xpcom/report.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/report.js b/chrome/content/zotero/xpcom/report.js index ae6fc360a..fd4039ee4 100644 --- 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(/]*>/)) { - 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 += '

' + escapeXML(arr.note) + '

\n'; } - // Wrap plaintext notes in

+ // Otherwise render markup normally else { - content += '

' + arr.note + '

\n'; + content += arr.note + '\n'; } } } @@ -98,13 +103,17 @@ Zotero.Report = new function() { for each(var note in arr.reportChildren.notes) { content += '
  • \n'; - if (note.note.substr(0, 1024).match(/]*>/)) { - content += note.note + '\n'; - } - // Wrap plaintext notes in

    - 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 += '

    ' + escapeXML(note.note) + '

    \n'; } + // Otherwise render markup normally + else { + content += note.note + '\n'; + } // Child note tags content += _generateTagsList(note);