diff --git a/chrome/content/zotero/xpcom/report.js b/chrome/content/zotero/xpcom/report.js index dc68170492..f6f609e70a 100644 --- a/chrome/content/zotero/xpcom/report.js +++ b/chrome/content/zotero/xpcom/report.js @@ -69,14 +69,7 @@ Zotero.Report.HTML = new function () { // Independent note if (obj['note']) { content += '\n\t\t\t'; - - let doc = domParser.parseFromString('
' - + obj.note - // Strip control characters (for notes that were - // added before item.setNote() started doing this) - .replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "") - + '
', "text/html"); - content += doc.body.innerHTML + '\n'; + content += getNoteHTML(obj.note); } } @@ -92,13 +85,7 @@ Zotero.Report.HTML = new function () { for (let note of obj.reportChildren.notes) { content += '\t\t\t\t\t
  • \n'; - let doc = domParser.parseFromString('
    ' - + note.note - // Strip control characters (for notes that were - // added before item.setNote() started doing this) - .replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "") - + '
    ', "text/html"); - content += doc.body.innerHTML + '\n'; + content += getNoteHTML(note.note); // Child note tags content += _generateTagsList(note); @@ -297,13 +284,7 @@ Zotero.Report.HTML = new function () { // Attachment note if (attachment.note) { content += '\t\t\t\t\t\t
    '; - if (attachment.note.substr(0, 1024).match(/]*>/)) { - content += attachment.note + '\n'; - } - // Wrap plaintext notes in

    - else { - content += '

    ' + escapeXML(attachment.note) + '

    \n'; - } + content += getNoteHTML(attachment.note); content += '\t\t\t\t\t
    '; } @@ -315,6 +296,22 @@ Zotero.Report.HTML = new function () { } + function getNoteHTML(note) { + // If HTML tag or entity, parse as HTML + if (note.match(/(<(p|ul|ol|div|a|br|b|i|u|strong|em( >))|&[a-z]+;|&#[0-9]+;)/)) { + let doc = domParser.parseFromString('
    ' + + note + // Strip control characters (for notes that were + // added before item.setNote() started doing this) + .replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "") + + '
    ', "text/html"); + return doc.body.innerHTML + '\n'; + } + // Otherwise, treat as plain text + return '

    ' + escapeXML(note) + '

    \n'; + } + + var escapeXML = function (str) { str = str.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ud800-\udfff\ufffe\uffff]/g, '\u2B1A'); return Zotero.Utilities.htmlSpecialChars(str);