Hi everyone,
I’m trying to adapt an existing “Zotero-Obsidian import template” to fit my own workflow. My goal is to group Zotero annotations (highlighted text + comments + tags) into predefined sections of my note based on the highlight color.
The idea is:
- highlight text in Zotero using different colors (e.g. red = critique, yellow = results, blue = methods)
-When importing into Obsidian, each annotation should automatically be written into a specific section of the template corresponding to its color
-I also use a CSS snippet to visually style the highlights, but the grouping itself should happen at import time via the template.
At the moment, the import works, but all annotations are inserted together and I have to manually sort them into the correct sections afterward. (see section “In-text annotations”)
I’ve tried filtering annotations in the template using their color (e.g. looping over annotations and checking the color field), but it doesn’t behave as expected.
My questions are:
Is it possible to group Zotero annotations by color directly in an Obsidian import template?
Which annotation field should be used for this (color, colorCategory, or something else)?
Is there a known limitation of the Zotero Integration / Citations / Highlightr plugins that would prevent this?
Thanks a lot for any pointers!
My template:
---
title: "{{title | escape}}"
year: {{date | format("YYYY")}}
authors: {{authors}}
citekey: {{citekey}}
tags: [{% for t in tags %}{{t.tag}}{% if not loop.last %}, {% endif %}{% endfor %}]
---
# {{title | escape}}
**Authors:** {{authors}}
**Year:** {{date | format("YYYY")}}
---
## Links
- [PDF]({{citekey}}.pdf)
- [Zotero item]({{zoteroSelectURI}})
---
## Abstract
{% if abstractNote %}
{{abstractNote | safe}}
{% else %}
*No abstract available.*
{% endif %}
---
> [!note]+ Atomic Notes
> {% persist "atomic-notes" %}
> Write the **core ideas of this paper in your own words**.
> - One idea per paragraph
> - Phrase ideas so they can stand alone
> - Link concepts to other notes
> {% endpersist %}
---
## Annotations
---
{% set groups = {
"magenta": {
"title": "🟣 Core concepts / hypotheses / frameworks",
"question": "What is the central idea or hypothesis?",
"persist": "synthesis-core-concepts"
},
"gray": {
"title": "⚫ Background / definitions / context",
"question": "What do I need to understand the paper?",
"persist": "synthesis-background"
},
"red": {
"title": "🔴 Contradictions / critical issues",
"question": "What conflicts with other studies or assumptions?",
"persist": "synthesis-contradictions"
},
"yellow": {
"title": "🟡 Key empirical results",
"question": "What did they actually find?",
"persist": "synthesis-results"
},
"blue": {
"title": "🔵 Methods & experimental design",
"question": "How was this measured or tested?",
"persist": "synthesis-methods"
},
"green": {
"title": "🟢 Mechanisms & ecological interpretation",
"question": "Why does this happen biologically/ecologically?",
"persist": "synthesis-mechanisms"
},
"orange": {
"title": "🟠 Limitations & uncertainties",
"question": "Where does this break down?",
"persist": "synthesis-limitations"
}
} %}
{% for color, g in groups %}
### {{ g.title }}
**Question answered:** _{{ g.question }}_
{% for a in annotations if a.annotatedText and a.colorCategory == color %}
> **Excerpt (p. {{ a.pageLabel }}):**
> "{{ a.annotatedText | safe }}"
{% if a.comment %}
> _Note:_ {{ a.comment | safe }}
{% endif %}
>
{% endfor %}
> [!summary]+ Synthesis — {{ g.title | replace("🟣","") | replace("⚫","") | replace("🔴","") | replace("🟡","") | replace("🔵","") | replace("🟢","") | replace("🟠","") }}
> {% persist g.persist %}
>
> {% endpersist %}
{% endfor %}
---
### In-text annotations
{% for annotation in annotations -%}
{%- if annotation.annotatedText -%}
{% if annotation.color %} <mark class="hltr-{{annotation.colorCategory | lower}}">"{{annotation.annotatedText | safe}}"</mark> {% else %} {{annotation.type | capitalize}} {% endif %}[Page {{annotation.pageLabel}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}})
{%- endif %}
{% if annotation.comment %}
{{annotation.comment | safe}} [Page {{annotation.pageLabel}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}})
{% endif %}
{%- if annotation.imageRelativePath %}
![[{{annotation.imageRelativePath}}]]
{%- endif %}
{% if annotation.allTags %}
{{annotation.allTags}}
{% endif %}
{% endfor -%}
My css snippet
/* Base Zotero highlight styling */
mark[class^="hltr-"] {
opacity: 0.75;
padding: 0.15em 0.4em;
border-radius: 6px;
line-height: 1.6;
font-weight: 500;
position: relative;
}
mark.hltr-magenta {
background-color: rgba(242, 114, 212, 0.25);
border-left: 4px solid #f272d4;
}
mark.hltr-magenta::before {
content: "Concept / Hypothesis";
font-size: 0.7em;
font-weight: 700;
color: #b24c9c;
margin-right: 0.5em;
}
mark.hltr-gray {
background-color: rgba(149, 165, 166, 0.25);
border-left: 4px solid #7f8c8d;
}
mark.hltr-gray::before {
content: "Background";
font-size: 0.7em;
font-weight: 700;
color: #5f6a6a;
margin-right: 0.5em;
}
mark.hltr-blue {
background-color: rgba(52, 152, 219, 0.25);
border-left: 4px solid #3498db;
}
mark.hltr-blue::before {
content: "Method";
font-size: 0.7em;
font-weight: 700;
color: #21618c;
margin-right: 0.5em;
}
mark.hltr-yellow {
background-color: rgba(255, 221, 87, 0.35);
border-left: 4px solid #f1c40f;
}
mark.hltr-yellow::before {
content: "Result";
font-size: 0.7em;
font-weight: 700;
color: #a67c00;
margin-right: 0.5em;
}
mark.hltr-green {
background-color: rgba(46, 204, 113, 0.25);
border-left: 4px solid #2ecc71;
}
mark.hltr-green::before {
content: "Mechanism";
font-size: 0.7em;
font-weight: 700;
color: #1e8449;
margin-right: 0.5em;
}
mark.hltr-purple {
background-color: rgba(178, 114, 242, 0.25);
border-left: 4px solid #b272f2;
}
mark.hltr-purple::before {
content: "Model / Theory";
font-size: 0.7em;
font-weight: 700;
color: #6c3483;
margin-right: 0.5em;
}
mark.hltr-orange {
background-color: rgba(230, 126, 34, 0.25);
border-left: 4px solid #e67e22;
}
mark.hltr-orange::before {
content: "Limitation / Question";
font-size: 0.7em;
font-weight: 700;
color: #935116;
margin-right: 0.5em;
}
mark.hltr-red {
background-color: rgba(231, 76, 60, 0.25);
border-left: 4px solid #e74c3c;
}
mark.hltr-red::before {
content: "Critical";
font-size: 0.7em;
font-weight: 700;
color: #922b21;
margin-right: 0.5em;
}