update: template docs
This commit is contained in:
parent
00f2872e7f
commit
24a6e44446
|
|
@ -25,7 +25,7 @@ Export with its' linked sub-notes to Obsidian:
|
|||
Use customized templates to import data from items/notes!
|
||||

|
||||
|
||||
[Template Document](./Template.md)
|
||||
[Template Usage](./TemplateUsage.md)
|
||||
|
||||
Discuss & contribute your templates [here](https://github.com/windingwind/zotero-better-notes/issues/23)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,429 @@
|
|||
# Template Documentation
|
||||
|
||||
This documentation is like a dictionary. For beginners, see [template usage](./TemplateUsage.md).
|
||||
|
||||
Use `Ctrl+F` to look up what you need and make your own template!
|
||||
|
||||
## Variables
|
||||
|
||||
### QuickInsert
|
||||
|
||||
> variables: link: string, subNoteItem, noteItem
|
||||
|
||||
### QuickBackLink
|
||||
|
||||
> variables: subNoteItem, noteItem
|
||||
|
||||
### QuickImport
|
||||
|
||||
> variables: subNoteLines: string[], subNoteItem, noteItem
|
||||
|
||||
### QuickNote
|
||||
|
||||
> variables: annotationItem, topItem
|
||||
|
||||
### ExportMDFileName
|
||||
|
||||
> variables: noteItem
|
||||
|
||||
### Text
|
||||
|
||||
> variables: -
|
||||
|
||||
### Item
|
||||
|
||||
> variables: topItem
|
||||
|
||||
### Note
|
||||
|
||||
> variables: topItem, noteItem, link
|
||||
|
||||
## Formats
|
||||
|
||||
### Line
|
||||
|
||||
Description: Normal line.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<p>Your Line Here</p>
|
||||
```
|
||||
|
||||
### Heading
|
||||
|
||||
Description: From h1 to h6.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<h1>Your Heding 1 Here</h1>
|
||||
<h2>Your Heding 2 Here</h2>
|
||||
```
|
||||
|
||||
### Highlight
|
||||
|
||||
Description: Highlight.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<p style="background-color:#dbeedd;">Text</p>
|
||||
```
|
||||
|
||||
### Strong
|
||||
|
||||
Description: **Strong text**. Put it in a `p`.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<strong>Your Text</strong>
|
||||
```
|
||||
|
||||
### Underline
|
||||
|
||||
Description: Underline text. Put it in a `p`.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<u>Your Text</u>
|
||||
```
|
||||
|
||||
### Deleteline
|
||||
|
||||
Description: Deleteline text. Put it in a `p`.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<span style="text-decoration: line-through">Your Text</span>
|
||||
```
|
||||
|
||||
### Link
|
||||
|
||||
Description: Link. Put it in a `p`.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<a href="zotero://replace/this/link">Link Text</a>
|
||||
```
|
||||
|
||||
### Number List
|
||||
|
||||
Description: Number List.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<ol>
|
||||
<li>First</li>
|
||||
<li>Second</li>
|
||||
<li>...</li>
|
||||
</ol>
|
||||
```
|
||||
|
||||
### Bullet List
|
||||
|
||||
Description: Bullet List.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<ul>
|
||||
<li>First</li>
|
||||
<li>Second</li>
|
||||
<li>...</li>
|
||||
</ul>
|
||||
```
|
||||
|
||||
### Sup & Sub Text
|
||||
|
||||
Description: $\text{The}^{sup} \ and \ \text{the}_{sub}$ text.
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<p>The<sup>sup</sup>and the<sub>sub</sub> text</p>
|
||||
```
|
||||
|
||||
### Block Quote
|
||||
|
||||
Description:
|
||||
|
||||
> Block Quote
|
||||
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<blockquote>
|
||||
<p>Text</p>
|
||||
</blockquote>
|
||||
```
|
||||
|
||||
### Monospaced
|
||||
|
||||
Description: `Monospaced`
|
||||
Template Type: None.
|
||||
Required Variable: None.
|
||||
|
||||
```html
|
||||
<pre>Text</pre>
|
||||
```
|
||||
|
||||
## General Fields
|
||||
|
||||
### Current Date
|
||||
|
||||
Description: Current Date.
|
||||
Required Variable: None.
|
||||
|
||||
```js
|
||||
<p>${new Date().toLocaleDateString()}</p>
|
||||
```
|
||||
|
||||
### Tags
|
||||
|
||||
Description: `item.getTags()` returns tags in list. Usually use `tags.includes("YourTag") ? do sth : do sth else`.
|
||||
Required Variable: any item/note/annotation.
|
||||
|
||||
```js
|
||||
<p>${topItem.getTags()}</p>
|
||||
```
|
||||
|
||||
## Note Fields
|
||||
|
||||
### Note Title
|
||||
|
||||
Description: Note Title. First line of note.
|
||||
Template Type: Note.
|
||||
Required Variable: noteItem/subNoteItem.
|
||||
|
||||
```js
|
||||
<p>${noteItem.getNoteTitle()}</p>
|
||||
```
|
||||
|
||||
### Note Content
|
||||
|
||||
Description: Note Content.
|
||||
Template Type: Note.
|
||||
Required Variable: noteItem/subNoteItem.
|
||||
|
||||
```js
|
||||
<p>${noteItem.getNote()}</p>
|
||||
```
|
||||
|
||||
### Note Link
|
||||
|
||||
Description: Note Link.
|
||||
Template Type: Note.
|
||||
Required Variable: noteItem/subNoteItem.
|
||||
|
||||
```js
|
||||
<p>
|
||||
<a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}">
|
||||
${noteItem.key}
|
||||
</a>
|
||||
</p>
|
||||
```
|
||||
|
||||
## Item Fields
|
||||
|
||||
### Title
|
||||
|
||||
Description: Item title.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>${topItem.getField("title")}</p>
|
||||
```
|
||||
|
||||
### Publisher/Journal
|
||||
|
||||
Description: Publisher/Journal.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>
|
||||
${(() => {
|
||||
if (topItem.itemType === "conferencePaper") {
|
||||
return;
|
||||
topItem.getField("conferenceName") ||
|
||||
topItem.getField("proceedingsTitle");
|
||||
}
|
||||
if (topItem.itemType === "journalArticle")
|
||||
return topItem.getField("publicationTitle");
|
||||
if (topItem.itemType === "report") return topItem.getField("institution");
|
||||
return topItem.getField("publicationTitle");
|
||||
})()}
|
||||
</p>
|
||||
```
|
||||
|
||||
### Authors
|
||||
|
||||
Description: Authors.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>
|
||||
${topItem
|
||||
.getCreators()
|
||||
.map((v) => v.firstName + " " + v.lastName)
|
||||
.join("; ")}
|
||||
</p>
|
||||
```
|
||||
|
||||
### Pub. date
|
||||
|
||||
Description: Pub. date.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>${topItem.getField("date")}</p>
|
||||
```
|
||||
|
||||
### Pub. date
|
||||
|
||||
Description: Publication date/time.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>${topItem.getField("date")}</p>
|
||||
```
|
||||
|
||||
### DOI
|
||||
|
||||
Description: DOI.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>
|
||||
<a href="https://doi.org/${topItem.getField('DOI')}">
|
||||
${topItem.getField("DOI")}
|
||||
</a>
|
||||
</p>
|
||||
```
|
||||
|
||||
### URL
|
||||
|
||||
Description: URL.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>
|
||||
<a href="${topItem.getField('url')}">${topItem.getField("url")}</a>
|
||||
</p>
|
||||
```
|
||||
|
||||
### CitationKey
|
||||
|
||||
Description: CitationKey.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>${topItem.citationKey ? topItem.citationKey : ""}</p>
|
||||
```
|
||||
|
||||
### PDF Link
|
||||
|
||||
Description: URL.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
<p>
|
||||
${((topItem) => {
|
||||
const getPDFLink = (_item) => {
|
||||
let libraryID = _item.libraryID;
|
||||
let library = Zotero.Libraries.get(libraryID);
|
||||
let itemKey = _item.key;
|
||||
let itemLink = "";
|
||||
if (library.libraryType === "user") {
|
||||
itemLink = `zotero://open-pdf/library/items/${itemKey}`;
|
||||
} else if (library.libraryType === "group") {
|
||||
itemLink = `zotero://open-pdf/groups/${library.id}/items/${itemKey}`;
|
||||
}
|
||||
return `<a href="${itemLink}">${_item.getFilename()}</a>`;
|
||||
};
|
||||
return Zotero.Items.get(topItem.getAttachments())
|
||||
.filter((i) => i.isPDFAttachment())
|
||||
.map((i) => getPDFLink(i))
|
||||
.join("\n");
|
||||
})(topItem)}
|
||||
</p>
|
||||
```
|
||||
|
||||
### Item Notes
|
||||
|
||||
Description: Walk all sub notes under an item. You can add your code inside the loop.
|
||||
Template Type: Item.
|
||||
Required Variable: topItem.
|
||||
|
||||
```js
|
||||
${itemNotes.map((noteItem)=>{
|
||||
// process each item note
|
||||
const noteLine = `<blockquote>
|
||||
${noteItem.getNote()}
|
||||
</blockquote>`;
|
||||
copyNoteImage(noteItem);
|
||||
return noteLine;
|
||||
}).join("\n")}
|
||||
```
|
||||
|
||||
### About Item Fields
|
||||
|
||||
The `noteItem` and `topItem` is a Zotero Item object. The general data can be accessed using the `getField()` method.
|
||||
|
||||
For example: `topItem.getField('title')` will return the title of the `topItem`.
|
||||
|
||||
```ts
|
||||
// Get Item Fields
|
||||
getField: (void)=>string;
|
||||
|
||||
// Get Authors
|
||||
getCreators: (void)=>{
|
||||
fieldMode: number,
|
||||
firstName: string, // may be empty
|
||||
lastName: string,
|
||||
creatorTypeID: number,
|
||||
}[];
|
||||
```
|
||||
|
||||
Find available fields of the selected item with the code below:
|
||||
|
||||
```js
|
||||
const item = ZoteroPane.getSelectedItems().shift();
|
||||
const usedFields = item.getUsedFields();
|
||||
Zotero.ItemFields.getAll()
|
||||
.filter((e) => usedFields.indexOf(e.id) >= 0)
|
||||
.map((e) => e.name);
|
||||
```
|
||||
|
||||
The result is like this (depending on the item you select):
|
||||
|
||||
```JSON
|
||||
[
|
||||
"0": "title"
|
||||
"1": "date"
|
||||
"2": "language"
|
||||
"3": "shortTitle"
|
||||
"4": "libraryCatalog"
|
||||
"5": "url"
|
||||
"6": "accessDate"
|
||||
"7": "pages"
|
||||
"8": "conferenceName"
|
||||
]
|
||||
```
|
||||
|
||||
or see https://aurimasv.github.io/z2csl/typeMap.xml for the detailed Zotero fields documentation.
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
# Template
|
||||
# Template Usage
|
||||
|
||||
v0.3.0 supports a new feature called _Template_
|
||||
This documentation is for beginners.
|
||||
|
||||
You can find it under the Workspace Window->Edit:
|
||||
If you want to customize your own template, see [template doc](./TemplateDoc.md). Post an issue if you need help.
|
||||
|
||||
You can find templates under the Workspace Tab/Window->Edit:
|
||||

|
||||
|
||||
## Add a template
|
||||
|
|
@ -34,7 +36,7 @@ Only the template with specific name will be called.
|
|||
- QuickNote: Called when creating a note from an annotation.
|
||||
- ExportMDFileName: Called when exporting notes to markdown in batch/linked notes to markdown mode. The rendered template will be file name.
|
||||
|
||||
## Templates
|
||||
## Template Examples
|
||||
|
||||
Welcome to share & contribute your template!
|
||||
|
||||
|
|
@ -255,127 +257,3 @@ Do some experiments
|
|||
<p></p>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Use a template
|
||||
|
||||
You can insert templates in 3 ways: `Text`, `Note`, and `Item`.
|
||||
|
||||
Templates with these keywords will show in the corresponding menu popup.
|
||||
|
||||
## Create a template
|
||||
|
||||
### Text
|
||||
|
||||
> variables: no special variables
|
||||
> A pure text template.
|
||||
|
||||
### Item
|
||||
|
||||
> variables: topItem
|
||||
> Select items and use `topItem`(a Zotero Item Object) to access its metadata. For example:
|
||||
|
||||
```js
|
||||
<p>${topItem.getField("title")}</p>
|
||||
```
|
||||
|
||||
Will be compiled to:
|
||||
|
||||
> YOLO-LITE: A Real-Time Object Detection Algorithm Optimized for Non-GPU Computers
|
||||
|
||||
### Note
|
||||
|
||||
> variables: topItem, noteItem, link
|
||||
> Select notes and use `topItem`(a Zotero Item Object) to access its metadata, `noteItem` to access the note. For example:
|
||||
|
||||
```js
|
||||
<h1>Note: ${noteItem.getNoteTitle()}</h1>
|
||||
${link}
|
||||
<p>${topItem.getField('title')}</p>
|
||||
```
|
||||
|
||||
Will be compiled to:
|
||||
|
||||
> # Note: Sensors in Papers
|
||||
>
|
||||
> [Sensors in Papers](http://:zotero://note/u/GCY9G2PZ/)
|
||||
> YOLO-LITE: A Real-Time Object Detection Algorithm Optimized for Non-GPU Computers
|
||||
|
||||
### QuickInsert
|
||||
|
||||
> variables: link: string, subNoteItem, noteItem
|
||||
|
||||
### QuickBackLink
|
||||
|
||||
> variables: subNoteItem, noteItem
|
||||
|
||||
### QuickImport
|
||||
|
||||
> variables: subNoteLines: string[], subNoteItem, noteItem
|
||||
|
||||
### QuickNote
|
||||
|
||||
> variables: annotationItem, topItem
|
||||
|
||||
### ExportMDFileName
|
||||
|
||||
> variables: noteItem
|
||||
|
||||
## API and Variables
|
||||
|
||||
This section is for developers who want to create a new template. Basic coding knowledge is required.
|
||||
To test & run scripts quickly, open Tools->Developer->Run Javascript.
|
||||
|
||||
### Item Fields
|
||||
|
||||
The `noteItem` and `topItem` is a Zotero Item object. The general data can be accessed using the `getField()` method.
|
||||
|
||||
For example: `topItem.getField('title')` will return the title of the `topItem`.
|
||||
|
||||
```ts
|
||||
// Get Item Fields
|
||||
getField: (void)=>string;
|
||||
|
||||
// Get Authors
|
||||
getCreators: (void)=>{
|
||||
fieldMode: number,
|
||||
firstName: string, // may be empty
|
||||
lastName: string,
|
||||
creatorTypeID: number,
|
||||
}[];
|
||||
```
|
||||
|
||||
Find available fields of the selected item with the code below:
|
||||
|
||||
```js
|
||||
const item = ZoteroPane.getSelectedItems().shift();
|
||||
const usedFields = item.getUsedFields();
|
||||
Zotero.ItemFields.getAll()
|
||||
.filter((e) => usedFields.indexOf(e.id) >= 0)
|
||||
.map((e) => e.name);
|
||||
```
|
||||
|
||||
The result is like this (depending on the item you select):
|
||||
|
||||
```JSON
|
||||
[
|
||||
"0": "title"
|
||||
"1": "date"
|
||||
"2": "language"
|
||||
"3": "shortTitle"
|
||||
"4": "libraryCatalog"
|
||||
"5": "url"
|
||||
"6": "accessDate"
|
||||
"7": "pages"
|
||||
"8": "conferenceName"
|
||||
]
|
||||
```
|
||||
|
||||
### Note Fields
|
||||
|
||||
```ts
|
||||
// Get Note Text in HTML
|
||||
getNote: (void)=>string;
|
||||
|
||||
// Get Note Title
|
||||
getNoteTitle: (void)=>string;
|
||||
```
|
||||
Loading…
Reference in New Issue