diff --git a/src/api.ts b/src/api.ts index 60b0db1..e337918 100644 --- a/src/api.ts +++ b/src/api.ts @@ -34,6 +34,7 @@ import { runTemplate, runTextTemplate, runItemTemplate, + runQuickInsertTemplate, } from "./modules/template/api"; import { getTemplateKeys, @@ -124,6 +125,7 @@ const template = { runTemplate, runTextTemplate, runItemTemplate, + runQuickInsertTemplate, getTemplateKeys, getTemplateText, setTemplate, diff --git a/src/modules/template/api.ts b/src/modules/template/api.ts index 83d9dc6..64890c5 100644 --- a/src/modules/template/api.ts +++ b/src/modules/template/api.ts @@ -3,7 +3,12 @@ import { itemPicker } from "../../utils/itemPicker"; import { getString } from "../../utils/locale"; import { fill, slice } from "../../utils/str"; -export { runTemplate, runTextTemplate, runItemTemplate }; +export { + runTemplate, + runTextTemplate, + runItemTemplate, + runQuickInsertTemplate, +}; const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; @@ -237,6 +242,26 @@ async function runItemTemplate( return renderedString; } +async function runQuickInsertTemplate( + noteItem: Zotero.Item, + targetNoteItem: Zotero.Item, + options: { + dryRun?: boolean; + } = {}, +) { + if (!noteItem || !targetNoteItem) return ""; + const link = addon.api.convert.note2link(noteItem, {}); + const content = await runTemplate( + "[QuickInsertV2]", + "link, linkText, subNoteItem, noteItem", + [link, noteItem.getNoteTitle().trim() || link, noteItem, targetNoteItem], + { + dryRun: options.dryRun, + }, + ); + return content; +} + async function getItemTemplateData() { // If topItems are pre-defined, use it without asking if (addon.data.template.picker.data.topItemIds?.length > 0) {