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

Issue with Note Template #835

Closed
2 tasks done
pinetreemoonlight opened this issue Dec 11, 2023 · 1 comment
Closed
2 tasks done

Issue with Note Template #835

pinetreemoonlight opened this issue Dec 11, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@pinetreemoonlight
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest Zotero and the latest plugin?

  • I have confirmed I'm using the latest Zotero and the latest plugin

Environment

  • OS: Win11
  • Zotero Version: 6.0.30
  • Plugin Version: 1.0.4

Describe the bug

I found this note template by the Better Notes author: #49 (comment)

${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) {
    const annots = _item
      .getAnnotations()
      .filter((_annot) => _annot.annotationColor === color);
    let annotations = [];
    for (let annot of annots) {
      const annotJson = await getAnnotation(annot);
      annotJson.attachmentItemID = _item.id;
      annotations.push(annotJson);
    }

    const editor =
      await Zotero.Knowledge4Zotero.knowledge.getWorkspaceEditorInstance();
    await editor.importImages(annotations);
    return Zotero.EditorInstanceUtilities.serializeAnnotations(annotations);
  }

  const attachments = Zotero.Items.get(topItem.getAttachments()).filter((i) =>
    i.isPDFAttachment()
  );
  let res = "";
  let colorYellow = "#ffd400";
  let colorRed = "#ff6666";
  let colorGreen = "#5fb236";
  let colorBlue = "#2ea8e5";
  let colorPerple = "#a28ae5";
  for (let attachment of attachments) {
    res += `<h2><p style="background-color:${colorYellow};">Yellow Heading</p></h2>
    ${(await getAnnotationsByColor(attachment, colorYellow)).html}
    `;
    res += `<h2><p style="background-color:${colorRed };">Red Heading</p></h2>
    ${(await getAnnotationsByColor(attachment, colorRed )).html}
    `;
    res += `<h2><p style="background-color:${colorGreen };">Green Heading</p></h2>
    ${(await getAnnotationsByColor(attachment, colorGreen )).html}
    `;
    res += `<h2><p style="background-color:${colorBlue };">Blue Heading</p></h2>
    ${(await getAnnotationsByColor(attachment, colorBlue )).html}
    `;
    res += `<h2><p style="background-color:${colorPerple };">Perple Heading</p></h2>
    ${(await getAnnotationsByColor(attachment, colorPerple )).html}
    `;
  }
  r(res);
})}

I entered it in Tools -> Developer -> Run Javascript, but I am getting error "SyntaxError: unexpected token: '{'"

I use Zotero ver. 6.0.30 and BetterNotes ver. 1.0.4 (latest for Zotero 6).

Am I doing something wrong? Do I need to paste the code somewhere else?

Debug Output

SyntaxError: unexpected token: '{'

Anything else?

No response

@pinetreemoonlight pinetreemoonlight added the bug Something isn't working label Dec 11, 2023
@pinetreemoonlight
Copy link
Author

pinetreemoonlight commented Dec 11, 2023

I found an answer in another thread. Would it be possible to edit the template in #227 to:

  1. show the annotations as bullet points under each heading
  2. to remove the parentheses for each annotation (" ")
  3. to remove the part in brackets for each annotation (author name, year and page number)?

I have no idea how to do it myself, so I am asking kindly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants