www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 26eebcfc4476af1095fab55fa21f9f14d8b4591e
parent 4871374673a33eaf272462167888c8e7c03ebf80
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 31 Jan 2017 13:56:45 -0500

More report note fixes

Restore handling of plaintext notes from before 835003dd6d3, and search
for a wider set of HTML indicators to avoid showing markup when no <p>
tags.

Diffstat:
Mchrome/content/zotero/xpcom/report.js | 41+++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 22 deletions(-)

diff --git 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('<div>' - + 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, "") - + '</div>', "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<li id="item_' + note.key + '">\n'; - let doc = domParser.parseFromString('<div>' - + 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, "") - + '</div>', "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<div class="note">'; - if (attachment.note.substr(0, 1024).match(/<p[^>]*>/)) { - content += attachment.note + '\n'; - } - // Wrap plaintext notes in <p> - else { - content += '<p class="plaintext">' + escapeXML(attachment.note) + '</p>\n'; - } + content += getNoteHTML(attachment.note); content += '\t\t\t\t\t</div>'; } @@ -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('<div>' + + note + // Strip control characters (for notes that were + // added before item.setNote() started doing this) + .replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "") + + '</div>', "text/html"); + return doc.body.innerHTML + '\n'; + } + // Otherwise, treat as plain text + return '<p class="plaintext">' + escapeXML(note) + '</p>\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);