remove: template type [Note]
fix: template rendering bugs resolve: #183
This commit is contained in:
parent
4b9e9bbc79
commit
9efdfa35bf
|
|
@ -6,7 +6,7 @@ Use `Ctrl+F` to look up what you need and make your own template!
|
|||
|
||||
## Stages
|
||||
|
||||
Some type of templates(Item, Note) support stages.
|
||||
Some type of templates(Item) support stages.
|
||||
|
||||
Code wrapped inside the stage will be called at a specific time.
|
||||
|
||||
|
|
@ -60,9 +60,7 @@ In other type of templates, the default stage is called.
|
|||
|
||||
### Note
|
||||
|
||||
> beforeloop stage: notes, copyNoteImage, editor, sharedObj(for temporary variables, shared by all stages)
|
||||
> default stage: noteItem, topItem, link, copyNoteImage, editor, sharedObj
|
||||
> afterloop stage: notes, copyNoteImage, editor, sharedObj
|
||||
> Removed after v0.7.15+
|
||||
|
||||
## Formats
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ Copy The Name & template text to a new template and save it!
|
|||
These templates can have different names. The keyword must be incluede in the template name.
|
||||
|
||||
- Text: indicate it's a normal template
|
||||
- Note: indicate it's a note template. Must select notes before inserting
|
||||
- Item: indicate it's an item template. Must select items before inserting
|
||||
|
||||
### System Templates
|
||||
|
|
@ -40,21 +39,3 @@ Only the template with specific name will be called.
|
|||
## Template Examples
|
||||
|
||||
Welcome to share & contribute your template! See [Templates From Community](https://github.com/windingwind/zotero-better-notes/issues/85) for more templates.
|
||||
|
||||
### [Note] with meta-data
|
||||
|
||||
```js
|
||||
<p><span style="background-color: #ffd40080">Note: ${link}</span></p>
|
||||
${topItem?`<p>Title: ${topItem.getField('title')}</p>
|
||||
<p>Author: ${topItem.getField('firstCreator')}</p>
|
||||
<p>Date: ${topItem.getField('date')}</p>`:''}
|
||||
```
|
||||
|
||||
### [Item] meta-data
|
||||
|
||||
```js
|
||||
<h2>Item Meta Data:</h2>
|
||||
<p>Title: ${topItem.getField('title')}</p>
|
||||
<p>Author: ${topItem.getField('firstCreator')}</p>
|
||||
<p>Date: ${topItem.getField('date')}</p>
|
||||
```
|
||||
|
|
|
|||
|
|
@ -65,9 +65,6 @@
|
|||
<menu id="menu_insertTextTemplate_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.insertTextTemplate;">
|
||||
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Text');" />
|
||||
</menu>
|
||||
<menu id="menu_insertNoteTemplate_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.insertNoteTemplate;">
|
||||
<menupopup id="menu_insertNoteTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Note');" />
|
||||
</menu>
|
||||
<menu id="menu_insertItemTemplate_betternotes" class="menu-betternotes" label="&zotero.__addonRef__.workspace.menu.insertItemTemplate;">
|
||||
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Item');" />
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -72,9 +72,6 @@
|
|||
<menu id="menu_insertTextTemplate" label="&zotero.__addonRef__.workspace.menu.insertTextTemplate;">
|
||||
<menupopup id="menu_insertTextTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Text');" />
|
||||
</menu>
|
||||
<menu id="menu_insertNoteTemplate" label="&zotero.__addonRef__.workspace.menu.insertNoteTemplate;">
|
||||
<menupopup id="menu_insertNoteTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Note');" />
|
||||
</menu>
|
||||
<menu id="menu_insertItemTemplate" label="&zotero.__addonRef__.workspace.menu.insertItemTemplate;">
|
||||
<menupopup id="menu_insertItemTemplatePopup" onpopupshowing="Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Item');" />
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -982,26 +982,6 @@ class EditorViews extends AddonBase {
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tag: "menu",
|
||||
id: "menupopup-insertNoteTemplate",
|
||||
checkExistanceParent: instance._popup,
|
||||
ignoreIfExists: true,
|
||||
attributes: [["label", "Insert Template (Note)"]],
|
||||
subElementOptions: [
|
||||
{
|
||||
tag: "menupopup",
|
||||
id: `menu_insert${instance._item.id}NoteTemplatePopup`,
|
||||
ignoreIfExists: true,
|
||||
attributes: [
|
||||
[
|
||||
"onpopupshowing",
|
||||
`Zotero.Knowledge4Zotero.ZoteroViews.updateTemplateMenu('Note', Zotero.Knowledge4Zotero.EditorController.activeEditor._popup.ownerDocument, '${instance._item.id}');`,
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
tag: "menu",
|
||||
id: "menupopup-insertItemTemplate",
|
||||
|
|
|
|||
|
|
@ -841,9 +841,7 @@ class ZoteroEvents extends AddonBase {
|
|||
) as Zotero.Item;
|
||||
|
||||
const ids = await this._Addon.ZoteroViews.openSelectItemsWindow();
|
||||
const items = (Zotero.Items.get(ids) as Zotero.Item[]).filter(
|
||||
(item: Zotero.Item) => item.isRegularItem()
|
||||
);
|
||||
const items = Zotero.Items.get(ids) as Zotero.Item[];
|
||||
if (items.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -890,9 +888,9 @@ class ZoteroEvents extends AddonBase {
|
|||
topItem, itemNotes, copyNoteImage, editor
|
||||
*/
|
||||
|
||||
const itemNotes: Zotero.Item[] = Zotero.Items.get(
|
||||
topItem.getNotes()
|
||||
) as Zotero.Item[];
|
||||
const itemNotes: Zotero.Item[] = topItem.isNote()
|
||||
? []
|
||||
: (Zotero.Items.get(topItem.getNotes()) as Zotero.Item[]);
|
||||
|
||||
renderredTemplate =
|
||||
await this._Addon.TemplateController.renderTemplateAsync(
|
||||
|
|
@ -923,132 +921,6 @@ class ZoteroEvents extends AddonBase {
|
|||
newLines.push("<p> </p>");
|
||||
}
|
||||
|
||||
if (newLines) {
|
||||
const html = newLines.join("\n");
|
||||
if (!targetItem) {
|
||||
console.log(html);
|
||||
|
||||
new CopyHelper()
|
||||
.addText(html, "text/html")
|
||||
.addText(this._Addon.NoteParse.parseHTMLToMD(html), "text/unicode")
|
||||
.copy();
|
||||
progressWindow.changeHeadline("Template Copied");
|
||||
} else {
|
||||
const forceMetadata = toCopyImage.length > 0;
|
||||
console.log(toCopyImage);
|
||||
await this._Addon.NoteUtils.addLineToNote(
|
||||
targetItem,
|
||||
html,
|
||||
-1,
|
||||
forceMetadata
|
||||
);
|
||||
await Zotero.DB.executeTransaction(async () => {
|
||||
for (const subNote of toCopyImage) {
|
||||
await Zotero.Notes.copyEmbeddedImages(subNote, targetItem);
|
||||
}
|
||||
});
|
||||
progressWindow.changeHeadline("Running Template Finished");
|
||||
}
|
||||
} else {
|
||||
progressWindow.changeHeadline("Running Template Failed");
|
||||
}
|
||||
progressWindow.startCloseTimer(5000);
|
||||
} else if (message.type === "insertNoteUsingTemplate") {
|
||||
/*
|
||||
message.content = {
|
||||
params: {templateName}
|
||||
}
|
||||
*/
|
||||
const targetItem = Zotero.Items.get(
|
||||
message.content.params.targetItemId
|
||||
) as Zotero.Item;
|
||||
const ids = await this._Addon.ZoteroViews.openSelectItemsWindow();
|
||||
const notes = (Zotero.Items.get(ids) as Zotero.Item[]).filter(
|
||||
(item: Zotero.Item) => item.isNote()
|
||||
);
|
||||
if (notes.length === 0) {
|
||||
return;
|
||||
}
|
||||
const progressWindow = this._Addon.ZoteroViews.showProgressWindow(
|
||||
"Running Template",
|
||||
message.content.params.templateName,
|
||||
"default",
|
||||
-1
|
||||
);
|
||||
const newLines: string[] = [];
|
||||
newLines.push("<p> </p>");
|
||||
|
||||
const toCopyImage: Zotero.Item[] = [];
|
||||
|
||||
const copyNoteImage = (noteItem: Zotero.Item) => {
|
||||
toCopyImage.push(noteItem);
|
||||
};
|
||||
|
||||
const editor =
|
||||
await this._Addon.WorkspaceWindow.getWorkspaceEditorInstance(
|
||||
"main",
|
||||
false
|
||||
);
|
||||
const sharedObj = {};
|
||||
|
||||
let renderredTemplate =
|
||||
await this._Addon.TemplateController.renderTemplateAsync(
|
||||
message.content.params.templateName,
|
||||
"notes, copyNoteImage, editor, sharedObj",
|
||||
[notes, copyNoteImage, editor, sharedObj],
|
||||
true,
|
||||
"beforeloop"
|
||||
);
|
||||
|
||||
if (renderredTemplate) {
|
||||
newLines.push(renderredTemplate);
|
||||
newLines.push("<p> </p>");
|
||||
}
|
||||
|
||||
for (const noteItem of notes) {
|
||||
/*
|
||||
Available variables:
|
||||
noteItem, topItem, link, copyNoteImage, editor
|
||||
*/
|
||||
let topItem = noteItem.parentItem;
|
||||
while (topItem && !topItem.isRegularItem()) {
|
||||
topItem = topItem.parentItem;
|
||||
}
|
||||
const linkURL = this._Addon.NoteUtils.getNoteLink(noteItem);
|
||||
const linkText = noteItem.getNoteTitle().trim();
|
||||
const link = `<p><a href="${linkURL}">${
|
||||
linkText ? linkText : linkURL
|
||||
}</a></p>`;
|
||||
|
||||
renderredTemplate =
|
||||
await this._Addon.TemplateController.renderTemplateAsync(
|
||||
message.content.params.templateName,
|
||||
"noteItem, topItem, link, copyNoteImage, editor, sharedObj",
|
||||
[noteItem, topItem, link, copyNoteImage, editor, sharedObj],
|
||||
true,
|
||||
"default"
|
||||
);
|
||||
|
||||
if (renderredTemplate) {
|
||||
newLines.push(renderredTemplate);
|
||||
newLines.push("<p> </p>");
|
||||
}
|
||||
}
|
||||
|
||||
renderredTemplate =
|
||||
await this._Addon.TemplateController.renderTemplateAsync(
|
||||
message.content.params.templateName,
|
||||
"notes, copyNoteImage, editor, sharedObj",
|
||||
[notes, copyNoteImage, editor, sharedObj],
|
||||
true,
|
||||
"afterloop"
|
||||
);
|
||||
|
||||
if (renderredTemplate) {
|
||||
newLines.push(renderredTemplate);
|
||||
newLines.push("<p> </p>");
|
||||
}
|
||||
|
||||
if (newLines) {
|
||||
const html = newLines.join("\n");
|
||||
if (!targetItem) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue