diff --git a/README.md b/README.md index 42059ef..b1d2431 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/TemplateDoc.md b/TemplateDoc.md new file mode 100644 index 0000000..1287760 --- /dev/null +++ b/TemplateDoc.md @@ -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 +
Your Line Here
+``` + +### Heading + +Description: From h1 to h6. +Template Type: None. +Required Variable: None. + +```html +Text
+``` + +### Strong + +Description: **Strong text**. Put it in a `p`. +Template Type: None. +Required Variable: None. + +```html +Your Text +``` + +### Underline + +Description: Underline text. Put it in a `p`. +Template Type: None. +Required Variable: None. + +```html +Your Text +``` + +### Deleteline + +Description: Deleteline text. Put it in a `p`. +Template Type: None. +Required Variable: None. + +```html +Your Text +``` + +### Link + +Description: Link. Put it in a `p`. +Template Type: None. +Required Variable: None. + +```html +Link Text +``` + +### Number List + +Description: Number List. +Template Type: None. +Required Variable: None. + +```html +Thesupand thesub text
+``` + +### Block Quote + +Description: + +> Block Quote + +Template Type: None. +Required Variable: None. + +```html +++``` + +### Monospaced + +Description: `Monospaced` +Template Type: None. +Required Variable: None. + +```html +Text
+
Text+``` + +## General Fields + +### Current Date + +Description: Current Date. +Required Variable: None. + +```js +
${new Date().toLocaleDateString()}
+``` + +### 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 +${topItem.getTags()}
+``` + +## Note Fields + +### Note Title + +Description: Note Title. First line of note. +Template Type: Note. +Required Variable: noteItem/subNoteItem. + +```js +${noteItem.getNoteTitle()}
+``` + +### Note Content + +Description: Note Content. +Template Type: Note. +Required Variable: noteItem/subNoteItem. + +```js +${noteItem.getNote()}
+``` + +### Note Link + +Description: Note Link. +Template Type: Note. +Required Variable: noteItem/subNoteItem. + +```js + +``` + +## Item Fields + +### Title + +Description: Item title. +Template Type: Item. +Required Variable: topItem. + +```js +${topItem.getField("title")}
+``` + +### Publisher/Journal + +Description: Publisher/Journal. +Template Type: Item. +Required Variable: topItem. + +```js ++ ${(() => { + 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"); + })()} +
+``` + +### Authors + +Description: Authors. +Template Type: Item. +Required Variable: topItem. + +```js ++ ${topItem + .getCreators() + .map((v) => v.firstName + " " + v.lastName) + .join("; ")} +
+``` + +### Pub. date + +Description: Pub. date. +Template Type: Item. +Required Variable: topItem. + +```js +${topItem.getField("date")}
+``` + +### Pub. date + +Description: Publication date/time. +Template Type: Item. +Required Variable: topItem. + +```js +${topItem.getField("date")}
+``` + +### DOI + +Description: DOI. +Template Type: Item. +Required Variable: topItem. + +```js ++ + ${topItem.getField("DOI")} + +
+``` + +### URL + +Description: URL. +Template Type: Item. +Required Variable: topItem. + +```js ++ ${topItem.getField("url")} +
+``` + +### CitationKey + +Description: CitationKey. +Template Type: Item. +Required Variable: topItem. + +```js +${topItem.citationKey ? topItem.citationKey : ""}
+``` + +### PDF Link + +Description: URL. +Template Type: Item. +Required Variable: topItem. + +```js ++ ${((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 `${_item.getFilename()}`; + }; + return Zotero.Items.get(topItem.getAttachments()) + .filter((i) => i.isPDFAttachment()) + .map((i) => getPDFLink(i)) + .join("\n"); + })(topItem)} +
+``` + +### 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 = `+ ${noteItem.getNote()} +`; + 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. diff --git a/Template.md b/TemplateUsage.md similarity index 75% rename from Template.md rename to TemplateUsage.md index bc5ac2d..90590dc 100644 --- a/Template.md +++ b/TemplateUsage.md @@ -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 ``` - -## 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 -
${topItem.getField("title")}
-``` - -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 -${topItem.getField('title')}
-``` - -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; -```