From 51db52a5ea44d6783e2baf3270ea4d2a4d81e532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Mon, 12 Oct 2020 17:01:24 +0300 Subject: [PATCH] Changes for note insertion in non-GoogleDocs --- chrome/content/zotero/xpcom/integration.js | 15 +++++---------- test/tests/integrationTest.js | 4 +++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index a77909a3e3..1f977fe323 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -586,10 +586,7 @@ Zotero.Integration.Interface.prototype.addEditCitation = async function (docFiel await this._session.init(false, false); docField = docField || await this._doc.cursorInField(this._session.data.prefs['fieldType']); - let citations = await this._session.cite(docField); - for (let citation of citations) { - await this._session.addCitation(citation._fieldIndex, await citation._field.getNoteIndex(), citation); - } + await this._session.cite(docField); if (this._session.data.prefs.delayCitationUpdates) { for (let citation of citations) { await this._session.writeDelayedCitation(citation._field, citation); @@ -1447,11 +1444,9 @@ Zotero.Integration.Session.prototype._processNote = function (item) { Zotero.logError(e); } } - // TODO: Later we'll need to convert note HTML to RDF. - // if (Zotero.Integration.currentSession._app.outputFormat == 'rtf') { - // text = return Zotero.RTFConverter.HTMLToRTF(text); - // }); - // } + text = text.replace(/[\u00A0-\u9999\&]/gim, function(i) { + return '&#'+i.charCodeAt(0)+';'; + }); return [text, citations, placeholderIDs]; }; @@ -1465,7 +1460,7 @@ Zotero.Integration.Session.prototype._insertNoteIntoDocument = async function (f citations.reverse(); placeholderIDs.reverse(); let fields = await this._doc.convertPlaceholdersToFields(citations.map(() => 'TEMP'), - placeholderIDs, this.data.prefs.noteType); + placeholderIDs, this.data.prefs.noteType, this.data.prefs.fieldType); let insertedCitations = await Promise.all(fields.map(async (field, index) => { let citation = new Zotero.Integration.Citation(new Zotero.Integration.CitationField(field, 'TEMP'), diff --git a/test/tests/integrationTest.js b/test/tests/integrationTest.js index 8638ec22e2..70064e1e26 100644 --- a/test/tests/integrationTest.js +++ b/test/tests/integrationTest.js @@ -110,10 +110,12 @@ describe("Zotero.Integration", function () { * Converts placeholders (which are text with links to https://www.zotero.org/?[placeholderID]) * to fields and sets their field codes to strings in `codes` in the reverse order of their appearance * @param {String[]} codes + * @param {String[]} placeholderIDs - the order of placeholders to be replaced * @param {Number} noteType - controls whether citations should be in-text or in footnotes/endnotes + * @param {Number} fieldType * @return {Field[]} */ - convertPlaceholdersToFields: function (codes, noteType) { + convertPlaceholdersToFields: function (codes, placeholderIDs, noteType, fieldType) { return codes.map(code => { let field = new DocumentPluginDummy.Field(this); field.code = code;