diff --git a/src/main/frontend/extensions/zotero/extractor.cljs b/src/main/frontend/extensions/zotero/extractor.cljs index 51d6ff1ae6..30aeac752c 100644 --- a/src/main/frontend/extensions/zotero/extractor.cljs +++ b/src/main/frontend/extensions/zotero/extractor.cljs @@ -13,13 +13,16 @@ (defmulti extract item-type) (defn citation-key [item] - (let [extra (-> item :data :extra) - citation (->> extra - (string/split-lines) - (filterv (fn [s] (string/includes? s "Citation Key: "))) - first)] - (when citation - (string/trim (string/replace citation "Citation Key: " ""))))) + (let [native-key (-> item :data :citation-key)] + (if-not (string/blank? native-key) + native-key + (let [extra (-> item :data :extra) + citation (->> extra + (string/split-lines) + (filterv (fn [s] (string/includes? s "Citation Key: "))) + first)] + (when citation + (string/trim (string/replace citation "Citation Key: " ""))))))) (defn title [item] (-> item :data :title)) diff --git a/src/test/frontend/extensions/zotero/extractor_test.cljs b/src/test/frontend/extensions/zotero/extractor_test.cljs index 5315009100..3394934118 100644 --- a/src/test/frontend/extensions/zotero/extractor_test.cljs +++ b/src/test/frontend/extensions/zotero/extractor_test.cljs @@ -8,6 +8,18 @@ (-> (rc/inline "fixtures/zotero.edn") (edn/read-string))) +(deftest citation-key-test + (let [item (:journal-article-sample-1 data)] + (testing "native Zotero citation key takes precedence over Extra" + (let [item (assoc-in item [:data :citation-key] "nativeKey2026")] + (is (= "nativeKey2026" (extractor/citation-key item))) + (is (= "@nativeKey2026" (:page-name (extractor/extract item)))))) + + (testing "older Better BibTeX key in Extra remains supported" + (is (= "efroniHowCombineTreeSearch2019" (extractor/citation-key item))) + (is (= "efroniHowCombineTreeSearch2019" + (extractor/citation-key (assoc-in item [:data :citation-key] ""))))))) + (deftest extract-test (testing "journal article" (let [{:keys [page-name properties]}