Display embedded images in item reports

Fixes #2002
This commit is contained in:
Martynas Bagdonas 2021-03-16 10:22:50 +02:00
parent 65329dbf27
commit 8799de5284
2 changed files with 16 additions and 9 deletions

View file

@ -30,7 +30,7 @@ Zotero.Report.HTML = new function () {
let domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"] let domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
.createInstance(Components.interfaces.nsIDOMParser); .createInstance(Components.interfaces.nsIDOMParser);
this.listGenerator = function* (items, combineChildItems) { this.listGenerator = function* (items, combineChildItems, libraryID) {
yield '<!DOCTYPE html>\n' yield '<!DOCTYPE html>\n'
+ '<html>\n' + '<html>\n'
+ ' <head>\n' + ' <head>\n'
@ -69,7 +69,7 @@ Zotero.Report.HTML = new function () {
// Independent note // Independent note
if (obj['note']) { if (obj['note']) {
content += '\n\t\t\t'; content += '\n\t\t\t';
content += getNoteHTML(obj.note); content += yield getNoteHTML(libraryID, obj);
} }
} }
@ -85,7 +85,7 @@ Zotero.Report.HTML = new function () {
for (let note of obj.reportChildren.notes) { for (let note of obj.reportChildren.notes) {
content += '\t\t\t\t\t<li id="item_' + note.key + '">\n'; content += '\t\t\t\t\t<li id="item_' + note.key + '">\n';
content += getNoteHTML(note.note); content += yield getNoteHTML(libraryID, note);
// Child note tags // Child note tags
content += _generateTagsList(note); content += _generateTagsList(note);
@ -95,8 +95,8 @@ Zotero.Report.HTML = new function () {
content += '\t\t\t\t</ul>\n'; content += '\t\t\t\t</ul>\n';
} }
// Chid attachments // Child attachments
content += _generateAttachmentsList(obj.reportChildren); content += yield _generateAttachmentsList(libraryID, obj.reportChildren);
} }
// Related items // Related items
@ -273,7 +273,7 @@ Zotero.Report.HTML = new function () {
} }
function _generateAttachmentsList(obj) { async function _generateAttachmentsList(libraryID, obj) {
var content = ''; var content = '';
if (obj.attachments && obj.attachments.length) { if (obj.attachments && obj.attachments.length) {
content += '\t\t\t\t<h3 class="attachments">' + escapeXML(Zotero.getString('itemFields.attachments')) + '</h3>\n'; content += '\t\t\t\t<h3 class="attachments">' + escapeXML(Zotero.getString('itemFields.attachments')) + '</h3>\n';
@ -292,7 +292,7 @@ Zotero.Report.HTML = new function () {
// Attachment note // Attachment note
if (attachment.note) { if (attachment.note) {
content += '\t\t\t\t\t\t<div class="note">'; content += '\t\t\t\t\t\t<div class="note">';
content += getNoteHTML(attachment.note); content += await getNoteHTML(libraryID, attachment);
content += '\t\t\t\t\t</div>'; content += '\t\t\t\t\t</div>';
} }
@ -304,7 +304,14 @@ Zotero.Report.HTML = new function () {
} }
function getNoteHTML(note) { async function getNoteHTML(libraryID, jsonItem) {
var note = jsonItem.note;
if (libraryID) {
var item = Zotero.Items.getByLibraryAndKey(libraryID, jsonItem.key);
if (item.isNote()) {
note = await Zotero.Notes.getExportableNote(item);
}
}
// If HTML tag or entity, parse as HTML // 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]+;)/)) { if (note.match(/(<(p|ul|ol|div|a|br|b|i|u|strong|em( >))|&[a-z]+;|&#[0-9]+;)/)) {
let doc = domParser.parseFromString('<div>' let doc = domParser.parseFromString('<div>'

View file

@ -510,7 +510,7 @@ function ZoteroProtocolHandler() {
default: default:
this.contentType = 'text/html'; this.contentType = 'text/html';
return Zotero.Utilities.Internal.getAsyncInputStream( return Zotero.Utilities.Internal.getAsyncInputStream(
Zotero.Report.HTML.listGenerator(items, combineChildItems), Zotero.Report.HTML.listGenerator(items, combineChildItems, params.libraryID),
function () { function () {
Zotero.logError(e); Zotero.logError(e);
return '<span style="color: red; font-weight: bold">Error generating report</span>'; return '<span style="color: red; font-weight: bold">Error generating report</span>';