Update signature for _serializeAnnotations and return object instead

This commit is contained in:
Martynas Bagdonas 2021-04-03 11:08:57 +03:00
parent 20022a5d7c
commit c3a74a22d7

View file

@ -159,7 +159,7 @@ class EditorInstance {
async insertAnnotations(annotations) { async insertAnnotations(annotations) {
await this._ensureNoteCreated(); await this._ensureNoteCreated();
let [html] = await this._serializeAnnotations(annotations); let { html } = await this._serializeAnnotations(annotations);
if (html) { if (html) {
this._postMessage({ action: 'insertHTML', pos: -1, html }); this._postMessage({ action: 'insertHTML', pos: -1, html });
} }
@ -198,7 +198,7 @@ class EditorInstance {
/** /**
* @param {Zotero.Item[]} annotations * @param {Zotero.Item[]} annotations
* @param {Boolean} skipEmbeddingItemData Do not add itemData to citation items * @param {Boolean} skipEmbeddingItemData Do not add itemData to citation items
* @return {String} - HTML string * @return {Object} Object with `html` string and `citationItems` array to embed into metadata container
*/ */
async _serializeAnnotations(annotations, skipEmbeddingItemData) { async _serializeAnnotations(annotations, skipEmbeddingItemData) {
let storedCitationItems = []; let storedCitationItems = [];
@ -292,7 +292,7 @@ class EditorInstance {
} }
html += '<p>' + imageHTML + otherHTML + '</p>\n'; html += '<p>' + imageHTML + otherHTML + '</p>\n';
} }
return [html, storedCitationItems]; return { html, citationItems: storedCitationItems };
} }
async _digestItems(ids) { async _digestItems(ids) {
@ -426,7 +426,8 @@ class EditorInstance {
} }
else if (type === 'zotero/annotation') { else if (type === 'zotero/annotation') {
let annotations = JSON.parse(data); let annotations = JSON.parse(data);
[html] = await this._serializeAnnotations(annotations); let { html: serializedHTML } = await this._serializeAnnotations(annotations);
html = serializedHTML;
} }
if (html) { if (html) {
this._postMessage({ action: 'insertHTML', pos, html }); this._postMessage({ action: 'insertHTML', pos, html });
@ -1104,12 +1105,10 @@ class EditorInstance {
jsonAnnotations.push(jsonAnnotation); jsonAnnotations.push(jsonAnnotation);
} }
let html = `<h1>${Zotero.getString('note.annotationsWithDate', new Date().toLocaleString())}</h1>\n`; let html = `<h1>${Zotero.getString('note.annotationsWithDate', new Date().toLocaleString())}</h1>\n`;
let [serializedHTML, storedCitationItems] = await editorInstance._serializeAnnotations(jsonAnnotations, true); let { html: serializedHTML, citationItems } = await editorInstance._serializeAnnotations(jsonAnnotations, true);
html += serializedHTML; html += serializedHTML;
citationItems = encodeURIComponent(JSON.stringify(citationItems));
storedCitationItems = encodeURIComponent(JSON.stringify(storedCitationItems)); html = `<div data-citation-items="${citationItems}" data-schema-version="${SCHEMA_VERSION}">${html}</div>`;
html = `<div data-citation-items="${storedCitationItems}" data-schema-version="${SCHEMA_VERSION}">${html}</div>`;
note.setNote(html); note.setNote(html);
await note.saveTx(); await note.saveTx();
return note; return note;