From 1bfef9c94c8b86e4dee16a7167ec678e6c2096ca Mon Sep 17 00:00:00 2001 From: RoBaaaT Date: Wed, 25 Oct 2023 11:29:21 +0200 Subject: [PATCH] Fix broken getCiteKey() resulting from recent BBT update 'citekey' has been renamed to 'citationKey' in BBT. See https://github.com/retorquere/zotero-better-bibtex/commit/63028dcd03ada843d6f55dfd6745bc92d6587ab2 --- content/mdnotes.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/content/mdnotes.js b/content/mdnotes.js index 6d670f6..cd27291 100644 --- a/content/mdnotes.js +++ b/content/mdnotes.js @@ -97,12 +97,11 @@ function getDateAdded(item) { return simpleISODate(date) } function getCiteKey(item) { - if (typeof Zotero.BetterBibTeX === "object" && Zotero.BetterBibTeX !== null) { - var bbtItem = Zotero.BetterBibTeX.KeyManager.get(item.getField("id")); - return bbtItem.citekey; - } - - return "undefined"; + try { + return item.getField('citationKey'); + } catch (_) { + return undefined; + } } function getLocalZoteroLink(item) { @@ -523,7 +522,7 @@ function replace_wildcards(str, args) { /** - * + * * @param {string} str The string to be replaced * @param {Object} args An array with the placeholder name as key and the (formatted) contents as values * @returns {string} A string with the placeholders replaced @@ -728,7 +727,7 @@ async function getZoteroNoteFileContents(item) { let fileContents = remove_invalid_placeholders( replace_placeholders(template, formattedPlaceholders) ); - + fileContents = replace_wildcards(fileContents, note); return { content: fileContents, name: fileName }; } @@ -953,10 +952,10 @@ Zotero.Mdnotes = async getRegularItemContents(item) { let metadata = getItemMetadata(item); let template = await readTemplate("Zotero Metadata Template"); - + // Add custom placeholders get_placeholder_contents(template, metadata); - + // Add formatting let formattedPlaceholders = format_placeholders(metadata); let newContents = remove_invalid_placeholders(