add: api.template.runQuickInsertTemplate
This commit is contained in:
parent
c6d4d93c5d
commit
a3b5ac8050
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue