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
[Question] Styling of annotaions with different color #49
Comments
Yes. You can paste your template here and I'll help you. |
Thanks. Actually I am trying to learn to create one and right now I don't have a template. |
@Sleepwalker6 You can try to click the menu 'Edit -> Preferences-> Advanced -> Config Editor -> I accept the risk!'
In Zotero pdf reader, adding the annotations to a note will use the above style. |
Thanks alot. |
Thanks, @zyx335588 . This is a solution using the Zotero 'Add to Note' function. |
Is there a way to do styling without modefying the config editor?@windingwind |
@Sleepwalker6
You can choose one that fits your workflow. |
Thanks, That is a great help. Forgive my lack of coding knowledge, but it would be great to be able to make more use of the zotero reader's main colors (Yellow, Green, Red, Blue, Purple). |
By the way, What @zyx335588 suggested would do the job. But it would be great to have it in the addon instead of editing zotero's main preference config. |
@Sleepwalker6 ${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);
})} You can modify the heading text. |
Thanks a lot. That was a great help. Just one question: |
You can add a filter for your custom color. Part of the template above. Just an example: let colorXXX = "#XXXXXX";
for (let attachment of attachments) {
res += `<h2><p style="background-color:${colorXXX};">XXX Heading</p></h2>
${(await getAnnotationsByColor(attachment, colorXXX)).html}
`;
} |
Thanks a lot for the help. One question: |
Zotero provides an 'add annotations to a new note' function. It can collect all annotations to a new note. |
try this: ${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);
}
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 = "";
for (let attachment of attachments) {
res += `<h2>${attachment.getFilename()}</h2>
${(await getAnnotationsByColor(attachment)).html}`;
}
r(res);
})} This is a multi-item version of Zotero's add annotation to note. |
Will close this issue. Please feel free to open it anytime |
Hi, thank you for the template, it works for me in Zotero 7 beta and the latest version of Better Notes. One question: could you help me modify the template to
|
(已经搜索过现有方案)您好!由于该模板(B形式)已经不适用zotero7,我尝试修改了但是因为没有该代码基础所以没能修改出来,能否麻烦您将版本升级到zotero7的版本,再次感谢您! |
Is it possible to add specific texts before or after annotations with different colors.
for example add "Important" before red annotaions or "Read more" before yellow annotaions.
The text was updated successfully, but these errors were encountered: