Skip to content

Commit

Permalink
Make sure cited items have better BibTeX keys before export
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic-DallOsto committed Aug 5, 2024
1 parent b5821ed commit 9fc2904
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/cita/sourceItemWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ class SourceItemWrapper extends ItemWrapper {
}
}

exportToFile(citationIndex?: number) {
async exportToFile(citationIndex?: number) {
this.loadCitations();
if (this.citations.length) {
// Zotero_File_Exporter is here https://github.com/zotero/zotero/blob/main/chrome/content/zotero/fileInterface.js#L43
Expand All @@ -732,6 +732,29 @@ class SourceItemWrapper extends ItemWrapper {
return tmpItem;
});

// Make sure items have better bibtex citation keys for export (if BetterBibTeX is installed) #145
if (Zotero.BetterBibTeX) {
await Zotero.BetterBibTeX.ready;
const proposed_keys = [];
for (const item of citedItems) {
const citationKeyMatch = Wikicite.getExtraField(
item,
"Citation Key",
);
if (citationKeyMatch.values.length != 1) {
const proposal: string =
Zotero.BetterBibTeX.KeyManager.propose(
item,
proposed_keys,
).citationKey;
proposed_keys.push(proposal);
Wikicite.setExtraField(item, "Citation Key", [
proposal,
]);
}
}
}

exporter.items = citedItems;
exporter.name = Wikicite.getString(
"wikicite.source-item.export-file.filename",
Expand Down

0 comments on commit 9fc2904

Please sign in to comment.