Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] Note Templates from Community #85

Closed
windingwind opened this issue Jul 10, 2022 · 7 comments
Closed

[Documentation] Note Templates from Community #85

windingwind opened this issue Jul 10, 2022 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@windingwind
Copy link
Owner

windingwind commented Jul 10, 2022

Please see https://github.com/windingwind/zotero-better-notes/discussions/categories/note-templates

@windingwind windingwind added the documentation Improvements or additions to documentation label Jul 10, 2022
@windingwind windingwind pinned this issue Jul 10, 2022
Repository owner locked and limited conversation to collaborators Jul 10, 2022
@windingwind
Copy link
Owner Author

windingwind commented Jul 14, 2022

Template: Text

[Text] today

<h1>TODO: ${new Date().toLocaleDateString()}</h1>
<h2>Tasks</h2>
<ul>
<li>
Read Paper 1
</li>
<li>
Do some experiments
</li>
</ul>
<blockquote>
<p>Insert more items with meta-data in workspace window-&gt;Edit</p>
</blockquote>
<p></p>
<h2>Done Tasks</h2>
<p></p>
<h2>Todo Tomorrow</h2>
<p></p>
</div>

[Text] Table

See https://github.com/windingwind/zotero-better-notes/blob/master/TemplateDoc.md#table
image

${(()=>{
const size = prompt("Table Size(row*column):", "4*3");
if(!size){
return "";
}
const row = Number(size.split("*")[0]);
const col = Number(size.split("*")[1]);
if(!row || !col){
return "";
}
const makeCell = ()=>"<td>\n</td>";
const makeRow = ()=>`<tr>${[...Array(col).keys()].map(makeCell).join("\n")}</tr>`;
return `<table>
${[...Array(row).keys()].map(makeRow).join("\n")}
</table>`;
})()}

@windingwind
Copy link
Owner Author

windingwind commented Jul 14, 2022

Template: Item(metadata)

[Item] metadata

Show Template Code
<h2>Item Meta Data:</h2>
<p>Title: ${topItem.getField('title')}</p>
<p>Author: ${topItem.getField('firstCreator')}</p>
<p>Date: ${topItem.getField('date')}</p>

[Item] item-notes with metadata:

Author: @zyx335588
image

Show Template Code
<h1>${topItem.getField('title')}</h1>
<h2 style="color:red; background-color: #efe3da;">💡 Meta Data</h2>
<table>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Title </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('title')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">Journal </p>
        </th>
        <td style="background-color:#f3faf4;">
            <p>${topItem.getField('publicationTitle')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">1<sup>st</sup> Author </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('firstCreator')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">Authors </p>
        </th>
        <td style="background-color:#f3faf4;">
            <p>${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Pub. date </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('date')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">DOI </p>
        </th>
        <td style="background-color:#f3faf4;">
            <a href="https://doi.org/${topItem.getField('DOI')}">${topItem.getField('DOI')}</a>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Archive </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('archive')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">Archive Location </p>
        </th>
        <td style="background-color:#f3faf4;">
            <p>${topItem.getField('archiveLocation')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Call No. </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('callNumber')}</p>
        </td>
    </tr>
</table>
${itemNotes.map((noteItem)=>{
const noteLine = `<h2  style="color:red; background-color: #efe3da;">📜 Note:  <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)
}" rel="noopener noreferrer nofollow">${noteItem.key}</a></h2>
<blockquote>
    ${noteItem.getNote()}
    <p style="background-color: pink;"><strong>Merge Date: </strong> ${new Date().toISOString().substr(0,10)+" "+ new Date().toTimeString()}</p>
</blockquote>
<p style="color:red; background-color: #efe3da;"><strong>📝 Comments</strong></p>
<blockquote>
    <p>Make your comments</p>
    <p></p>
</blockquote>`;
copyNoteImage(noteItem);
return noteLine;
}).join("\n")}

[Item] metadata for CS

Modified on the previous template. Auto-adjust metadata according to item type.
image

Show Template Code
<h2>${topItem.getField('title')}</h2>
<table>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Title </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('title')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">${(()=>{
              if(topItem.itemType === "conferencePaper") return "Conference";
              if(topItem.itemType === "journalArticle") return "Journal";
              if(topItem.itemType === "report") return "Publisher";
              return "Publisher";})()}</p>
        </th>
        <td style="background-color:#f3faf4;"><p>${(()=>{
              if(topItem.itemType === "conferencePaper") {
                const res =  topItem.getField("conferenceName");
                return res?res:topItem.getField("proceedingsTitle");
              };
              if(topItem.itemType === "journalArticle") return topItem.getField("publicationTitle");
              if(topItem.itemType === "report") return topItem.getField("institution");
              return topItem.getField("publicationTitle");})()}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Authors </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">Pub. date </p>
        </th>
        <td style="background-color:#f3faf4;">
            <p>${topItem.getField('date')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">DOI </p>
        </th>
        <td style="background-color:#dbeedd;">
            <a href="https://doi.org/${topItem.getField('DOI')}">${topItem.getField('DOI')}</a>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">URL</p>
        </th>
        <td style="background-color:#f3faf4;">
            <p>${topItem.getField('url')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">CitationKey</p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.citationKey?topItem.citationKey:''}</p>
        </td>
    </tr>
</table>

Extra Metadata Fields:

Item Link. Click to open the PDF attachment.
image

Show Template Code
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">PDF Attachment</p>
        </th>
        <td style="background-color:#f3faf4;">
            <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>
        </td>
    </tr>

[Item] item-notes with item&note metadata

Author: @pyfriday
image

Show Template Code
<h2  style="color:red; background-color: #efe3da;">📜 Note:  ${link}</a></h2>
<blockquote>
    ${noteItem.getNote()}
    <p style="background-color: pink;"><strong>Merge Date: </strong> ${new Date().toISOString().substr(0,10)+" "+ new Date().toTimeString()}</p>
${topItem?  `<h3 style="color:red; background-color: #efe3da;">💡 Meta Data</h3>
<blockquote>
<table>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Title </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('title')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">Journal </p>
        </th>
        <td style="background-color:#f3faf4;">
            <p>${topItem.getField('publicationTitle')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#f3faf4;">
            <p style="text-align: right">Authors </p>
        </th>
        <td style="background-color:#f3faf4;">
            <p>${topItem.getCreators().map((v)=>v.firstName+" "+v.lastName).join("; ")}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">Pub. date </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('date')}</p>
        </td>
    </tr>
    <tr>
        <th style="background-color:#dbeedd;">
            <p style="text-align: right">IF </p>
        </th>
        <td style="background-color:#dbeedd;">
            <p>${topItem.getField('callNumber')}</p>
        </td>
    </tr>
</table>
</blockquote>
</blockquote>
<p style="color:red; background-color: #efe3da;"><strong>📝 Comments</strong></p>
<blockquote>
    <p>Make your comments</p>
    <p></p>
</blockquote>`  : ""}

@windingwind
Copy link
Owner Author

windingwind commented Aug 10, 2022

Template: Item(annotations by color)

[Item] collect annotations by color

Author: @windingwind
Discuss: #49
Type: A
image

image

Show Template Code
${await new Promise(async (r) => {
  async function getAnnotation(item) {
    try {
      if (!item || !item.isAnnotation()) {
        return null;
      }
      let json = await Zotero.Annotations.toJSON(item);
      json.id = item.key;
      delete json.key;
      for (let key in json) {
        json[key] = json[key] || "";
      }
      json.tags = json.tags || [];
      return json;
    } catch (e) {
      Zotero.logError(e);
      return null;
    }
  }

  async function getAnnotationsByColor(_item, colorFilter) {
    const annots = _item.getAnnotations().filter(colorFilter);
    if (annots.length === 0) {
      return {
        html: "",
      };
    }
    let annotations = [];
    for (let annot of annots) {
      const annotJson = await getAnnotation(annot);
      annotJson.attachmentItemID = _item.id;
      annotations.push(annotJson);
    }

    if (!editor) {
      alert("No active note editor detected. Please open workspace.");
      return r("");
    }
    await editor.importImages(annotations);
    return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
  }

  const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
    i.isPDFAttachment()
  );
  let res = "";
  const colors = ["#ffd400", "#ff6666", "#5fb236", "#2ea8e5", "#a28ae5"];
  const colorNames = ["Yellow", "Red", "Green", "Blue", "Purple"];
  for (let attachment of attachments) {
    res += `<h1>${attachment.getFilename()}</h1>`;
    for (let i in colors) {
      const renderedAnnotations = (
        await getAnnotationsByColor(
          attachment,
          (_annot) => _annot.annotationColor === colors[i]
        )
      ).html;
      if (renderedAnnotations) {
        res += `<h2><p style="background-color:${colors[i]};">${colorNames[i]} Annotations</p></h2>\n${renderedAnnotations}`;
      }
    }
    const renderedAnnotations = (
      await getAnnotationsByColor(
        attachment,
        (_annot) => !colors.includes(_annot.annotationColor)
      )
    ).html;
    if (renderedAnnotations) {
      res += `<h2><p>Other Annotations</p></h2>\n${renderedAnnotations}`;
    }
  }
  r(res);
})}

[Item] collect annotations by color

Author: @windingwind
Discuss: #49
Type: B

image

Show Template Code
${await new Promise(async (r) => {
  async function getAnnotation(item) {
    try {
      if (!item || !item.isAnnotation()) {
        return null;
      }
      let json = await Zotero.Annotations.toJSON(item);
      json.id = item.key;
      delete json.key;
      for (let key in json) {
        json[key] = json[key] || "";
      }
      json.tags = json.tags || [];
      return json;
    } catch (e) {
      Zotero.logError(e);
      return null;
    }
  }

  async function getAnnotationsByColor(_item, color) {
    let annots = _item
      .getAnnotations()
    annots = color ? 
      annots.filter((_annot) => _annot.annotationColor === color) :
      annots;
    let annotations = [];
    for (let annot of annots) {
      const annotJson = await getAnnotation(annot);
      annotJson.attachmentItemID = _item.id;
      annotations.push(annotJson);
    }
    if (!editor) {
      alert("No active note editor detected. Please open workspace.");
      return r("");
    }
    await editor.importImages(annotations);
    return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
  }

  const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
    i.isPDFAttachment()
  );
  let res = "";
  for (let attachment of attachments) {
    res += `<h2>${attachment.getFilename()}</h2>
${(await getAnnotationsByColor(attachment)).html}`;
  }
  r(res);
})}

@windingwind
Copy link
Owner Author

Template: Item(notes)

[Item] collect item-notes to a new item-note and add a link to the main note

Author: @windingwind
Discuss: #86
image

${await new Promise(async (r) => {
  const newNote = new Zotero.Item("note");
  newNote.libraryID = topItem.libraryID;
  newNote.parentID = topItem.id;
  newNote.setNote(
    `<div data-schema-version="8">
    <h2>${topItem.getField('title')}</h2>
    ${Zotero.Items.get(item.getNotes()).map(_note => `<p>
      <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(_note)}">
        ${_note.getNoteTitle()}
      </a>
    </p>`).join('\n')}
    </div>`
  );
  await newNote.saveTx();

  let res = `<p>
    <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(newNote)}">
      ${newNote.getNoteTitle()}
    </a>
  </p>`;
  r(res);
})}

@windingwind
Copy link
Owner Author

windingwind commented Aug 12, 2022

Template: Item(annotations by tag)

Require Better Notes version>=0.6.19

Usage: Select some items, input tags(split by ,), and the annotations under these items will be collected in the main note.

[Item] collect annotations by tag

Author: @windingwind
Discuss: https://forums.zotero.org/discussion/comment/414433/#Comment_414433

Input tags once and search annotations with these tags in the selected items.

  • Item 1
    • Tag 1
      • annotation 1
      • annotation 2
    • Tag 2
      • annotation 3
    • ...
  • Item 2
    • Tag 1
      • annotation 4
    • Tag 2
      • annotation 5

image

Show Template Code
// @beforeloop-begin
${(()=>{
sharedObj.tagRaw = prompt("Please input tags. Split with ',':", "");
return "";
})()}
// @beforeloop-end
// @default-begin
${await new Promise(async (r) => {
  async function getAnnotation(item) {
    try {
      if (!item || !item.isAnnotation()) {
        return null;
      }
      let json = await Zotero.Annotations.toJSON(item);
      json.id = item.key;
      delete json.key;
      for (let key in json) {
        json[key] = json[key] || "";
      }
      json.tags = json.tags || [];
      return json;
    } catch (e) {
      Zotero.logError(e);
      return null;
    }
  }

  async function getAnnotationsByTag(_item, tag) {
    let annots = _item.getAnnotations();
    annots = tag.length? 
      annots.filter((_annot) => _annot.getTags().map(_t=>_t.tag).includes(tag)) :
      annots;
    let annotations = [];
    for (let annot of annots) {
      const annotJson = await getAnnotation(annot);
      annotJson.attachmentItemID = _item.id;
      annotations.push(annotJson);
    }
      if (!editor) {
        alert("No active note editor detected. Please open workspace.");
        return r("");
      }
      await editor.importImages(annotations);
      return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
    }
  const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
    i.isPDFAttachment()
  );
  let res = "";
  if(!sharedObj.tagRaw){
    return;
  }
  res += `<h1>${topItem.getField('title')}</h1>`;
  for (let attachment of attachments) {
    res += `<h2>${attachment.getFilename()}</h2>`;
    for(tag of sharedObj.tagRaw.split(',').filter(t=>t.length)){
      res += `<h3>Tag: ${tag}</h3>`;
      const tags = (await getAnnotationsByTag(attachment, tag)).html
      res += tags ? tags : "<p>No result</p>";
  }
  }
  r(res);
})}
// @default-end

[Item] collect annotations by tag separately

Author: @windingwind
Discuss: https://forums.zotero.org/discussion/comment/414541/#Comment_414541

Input tags for every selected item and search annotations with these tags in the selected items.

  • Item 1
    • Tag 1
      • annotation 1
      • annotation 2
    • Tag 2
      • annotation 3
    • ...
  • Item 2
    • Tag 3
      • annotation 4
    • Tag 4
      • annotation 5

image

Show Template Code
// @default-begin
${await new Promise(async (r) => {
  async function getAnnotation(item) {
    try {
      if (!item || !item.isAnnotation()) {
        return null;
      }
      let json = await Zotero.Annotations.toJSON(item);
      json.id = item.key;
      delete json.key;
      for (let key in json) {
        json[key] = json[key] || "";
      }
      json.tags = json.tags || [];
      return json;
    } catch (e) {
      Zotero.logError(e);
      return null;
    }
  }
  async function getAnnotationsByTag(_item, tag) {
    let annots = _item.getAnnotations();
    annots = tag.length? 
      annots.filter((_annot) => _annot.getTags().map(_t=>_t.tag).includes(tag)) :
      annots;
    let annotations = [];
    for (let annot of annots) {
      const annotJson = await getAnnotation(annot);
      annotJson.attachmentItemID = _item.id;
      annotations.push(annotJson);
    }
    if (!editor) {
      alert("No active note editor detected. Please open workspace.");
      return r("");
    }
    await editor.importImages(annotations);
    return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
  }
  const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
    i.isPDFAttachment()
  );
  let res = "";
  const tagRaw = prompt(`Source: ${topItem.getField('title')}
Please input tags. Split with ',':`, "");
  if(!tagRaw){
    return;
  }
  res += `<h1>${topItem.getField('title')}</h1>`;
  for (let attachment of attachments) {
    res += `<h2>${attachment.getFilename()}</h2>`;
    for(tag of tagRaw.split(',').filter(t=>t.length)){
      res += `<h3>Tag: ${tag}</h3>`;
      const tags = (await getAnnotationsByTag(attachment, tag)).html
      res += tags ? tags : "<p>No result</p>";
  }
  }
  r(res);
})}
// @default-end

[Item] collect annotations and notes by tag

Author: @windingwind
Discuss: https://forums.zotero.org/discussion/comment/414541/#Comment_414541

Input tags once and search annotations & notes with these tags in the selected items.

  • Item 1
    • Tag 1
      • note link 1
      • annotation 1
    • Tag 2
      • annotation 2
    • ...
  • Item 2
    • Tag 1
      • note link 2
    • Tag 2
      • annotation 3

image

Show Template Code
// @beforeloop-begin
${(()=>{
sharedObj.tagRaw = prompt("Please input tags. Split with ',':", "");
return "";
})()}
// @beforeloop-end
// @default-begin
${await new Promise(async (r) => {
  async function getAnnotation(item) {
    try {
      if (!item || !item.isAnnotation()) {
        return null;
      }
      let json = await Zotero.Annotations.toJSON(item);
      json.id = item.key;
      delete json.key;
      for (let key in json) {
        json[key] = json[key] || "";
      }
      json.tags = json.tags || [];
      return json;
    } catch (e) {
      Zotero.logError(e);
      return null;
    }
  }
  async function getAnnotationsByTag(_item, tag) {
    let annots = _item.getAnnotations();
    annots = tag.length? 
      annots.filter((_annot) => _annot.getTags().map(_t=>_t.tag).includes(tag)) :
      annots;
    let annotations = [];
    for (let annot of annots) {
      const annotJson = await getAnnotation(annot);
      annotJson.attachmentItemID = _item.id;
      annotations.push(annotJson);
    }
    if (!editor) {
      alert("No active note editor detected. Please open workspace.");
      return r("");
    }
    await editor.importImages(annotations);
    return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
  }
  const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
    i.isPDFAttachment()
  );
  let res = "";
  if(!sharedObj.tagRaw){
    return;
  }
  res += `<h1>${topItem.getField('title')}</h1>`;
  for (let attachment of attachments) {
    res += `<h2>${attachment.getFilename()}</h2>`;
    for(tag of sharedObj.tagRaw.split(',').filter(t=>t.length)){
      res += `<h3>Tag: ${tag}</h3>`;
      const tags = (await getAnnotationsByTag(attachment, tag)).html
      res += tags ? tags : "<p>No result</p>";
    }
  }
  res += `<h2>Notes</h2>`;
  const notesWithTags = `${itemNotes.filter(noteItem=>{
    for(tag of sharedObj.tagRaw.split(',').filter(t=>t.length)){
      if(noteItem.getTags().map(_t=>_t.tag).includes(tag)){
        return true;
}
}
return false;
}).map((noteItem)=>{
const noteLine = `<p style="color:red; background-color: #efe3da;">📜 Article Note:  <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)
}" rel="noopener noreferrer nofollow">${noteItem.getNoteTitle()?noteItem.getNoteTitle():Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}</a></p>
<p>tags: ${noteItem.getTags().map(_t=>_t.tag).join(', ')}</p>
<p> </p>`;
return noteLine;
}).join("\n")}`
res += notesWithTags  ? notesWithTags  : '<p>No result</p>'
  r(res);
})}
// @default-end

[Item] collect item-notes by tag

Author: @windingwind
Discuss: https://forums.zotero.org/discussion/comment/414541/#Comment_414541

Input tags once and search item-notes with these tags in the selected items.

Show Template Code
// @beforeloop-begin
${(()=>{
sharedObj.tagRaw = prompt("Please input tags. Split with ',':", "");
return "";
})()}
// @beforeloop-end
// @default-begin
${await new Promise(async (r) => {
  let res = "";

  if(!sharedObj.tagRaw){
    return;
  }
  res += `<h1>${topItem.getField('title')}</h1>`;
  res += `<h2>Notes</h2>`;
  const notesWithTags = `${itemNotes.filter(noteItem=>{
    for(tag of sharedObj.tagRaw.split(',').filter(t=>t.length)){
      if(noteItem.getTags().map(_t=>_t.tag).includes(tag)){
        return true;
}
}
return false;
}).map((noteItem)=>{
const noteLine = `<p style="color:red; background-color: #efe3da;">📜 Article Note:  <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)
}" rel="noopener noreferrer nofollow">${noteItem.getNoteTitle()?noteItem.getNoteTitle():Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}</a></p>
<p>tags: ${noteItem.getTags().map(_t=>_t.tag).join(', ')}</p>
<p> </p>`;
return noteLine;
}).join("\n")}`
res += notesWithTags  ? notesWithTags  : '<p>No result</p>'
  r(res);
})}
// @default-end

[Item] collect item-notes by tag seperately

Author: @windingwind
Discuss: https://forums.zotero.org/discussion/comment/414541/#Comment_414541

Input tags once and search item-notes with these tags in the selected items.

Show Template Code
// @default-begin
${await new Promise(async (r) => {
  let res = "";
  let tagRaw = prompt("Please input tags. Split with ',':", "");
  if(!tagRaw){
    return;
  }
  res += `<h1>${topItem.getField('title')}</h1>`;
  res += `<h2>Notes</h2>`;
  const notesWithTags = `${itemNotes.filter(noteItem=>{
    for(tag of sharedObj.tagRaw.split(',').filter(t=>t.length)){
      if(noteItem.getTags().map(_t=>_t.tag).includes(tag)){
        return true;
}
}
return false;
}).map((noteItem)=>{
const noteLine = `<p style="color:red; background-color: #efe3da;">📜 Article Note:  <a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)
}" rel="noopener noreferrer nofollow">${noteItem.getNoteTitle()?noteItem.getNoteTitle():Zotero.Knowledge4Zotero.knowledge.getNoteLink(noteItem)}</a></p>
<p>tags: ${noteItem.getTags().map(_t=>_t.tag).join(', ')}</p>
<p> </p>`;
return noteLine;
}).join("\n")}`
res += notesWithTags  ? notesWithTags  : '<p>No result</p>'
  r(res);
})}
// @default-end

[Item] all annotations and notes by tag

Author: @windingwind
Discuss: #191

Search annotations & notes with these tags in the selected items.

  • Tag 1
    • note link 1
    • annotation 1
    • annotation 2
  • Tag 2
    • note link 2
  • Tag 3
    • annotation 3

image

Show Template Code
// @beforeloop-begin
${(() => {
  sharedObj.tagsDict = {};
  sharedObj.updateData = (item, tag) => {
    if (!(tag in sharedObj.tagsDict)) {
      sharedObj.tagsDict[tag] = [];
    }
    sharedObj.tagsDict[tag].push(item);
  };
  if (!editor) {
    alert("No active note editor detected. Please open workspace.");
    sharedObj.error = true;
  }
  return "";
})()}
// @beforeloop-end
// @default-begin
${await new Promise(async (r) => {
  if (sharedObj.error) {
    return;
  }

  if (topItem.isRegularItem()) {
    const annotations = [];
    const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
      i.isPDFAttachment()
    );
    attachments.forEach((i) => {
      annotations.splice(0, 0, ...i.getAnnotations());
    });
    const notes = Zotero.Items.get(topItem.getNotes());
    annotations.splice(0, 0, ...notes);
    annotations.forEach((annotation) =>
      annotation
        .getTags()
        .map((tag) => tag.tag)
        .forEach((tag) => {
          sharedObj.updateData(annotation, tag);
        })
    );
    Zotero.Items.get(topItem.getNotes()).forEach((note) =>
      note
        .getTags()
        .map((tag) => tag.tag)
        .forEach((tag) => {
          sharedObj.updateData(note, tag);
        })
    );
  } else if (topItem.isNote()) {
    topItem
      .getTags()
      .map((tag) => tag.tag)
      .forEach((tag) => {
        sharedObj.updateData(topItem, tag);
      });
  }
  return r("");
})}
// @default-end
// @afterloop-begin
${await new Promise(async (r) => {
  if (sharedObj.error) {
    return;
  }
  console.log(sharedObj);
  let res = "";
  for (const tag in sharedObj.tagsDict) {
    res += `<h1>Tag: ${tag}</h1>\n`;
    for (const note of sharedObj.tagsDict[tag].filter((item) =>
      item.isNote()
    )) {
      res += `<p><a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(
        note
      )}">${note.getNoteTitle()}</a></p>\n`;
    }
    res += await Zotero.Knowledge4Zotero.NoteParse.parseAnnotationHTML(
      editor._item,
      sharedObj.tagsDict[tag].filter((item) => item.isAnnotation())
    );
    res += "\n";
  }
  return r(res);
})}
// @afterloop-end

@windingwind
Copy link
Owner Author

Template: QuickNoteV2

Usage: Create note from annotation.

[QuickNoteV2]
Attach the title of the item when adding the quick note to the main note.
If the note has no comments, use "annotation" as the default title.
Author: @Bridge0415
Discuss: #148

${await new Promise(async (r) => {
let res = "annotation"
if(annotationItem.annotationComment){
res = ""
res += Zotero.Knowledge4Zotero.parse.parseMDToHTML(annotationItem.annotationComment);
}
res +="<blockquote><i>《"
res +=topItem.getField('title')
res += "》</i></blockquote>"
res += await 
Zotero.Knowledge4Zotero.parse.parseAnnotationHTML(noteItem, [annotationItem], true);
r(res);})}

@windingwind
Copy link
Owner Author

Template: Item(notes)

[Item] note links

Insert links of selected notes.
Author: @windingwind

<p><a href="${Zotero.Knowledge4Zotero.knowledge.getNoteLink(topItem)}">${topItem.getNoteTitle().trim() ? topItem.getNoteTitle().trim() : Zotero.Knowledge4Zotero.knowledge.getNoteLink(topItem)}</a></p>

@windingwind windingwind unpinned this issue Nov 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant