Skip to content

Instantly share code, notes, and snippets.

@QWxleA
Last active February 28, 2025 16:32
Show Gist options
  • Save QWxleA/c7f08e8feded332736a6b376045d0fe4 to your computer and use it in GitHub Desktop.
Save QWxleA/c7f08e8feded332736a6b376045d0fe4 to your computer and use it in GitHub Desktop.
Obsidian zotero template for use with "obsidian-zotero-integration" plugin

QWxlea's over-engineered zotero template

Faq

What are these %% begin id-pn2xitti%% and %% end id-pn2xitti %% and ^pn2xitti? These are the persistance-markers of the indivual highlights, and the reference-id to that highlight.

The markers are meant for the importer. It will skip all text within those markers, so they stay when updating a zotero-import. Removing a marked block does not work well, it will not be reimported. Don't know how to fix that. If you want to reimport a highlight-block, best is to change the highlight in zotero (for example change the color). This will update the id, and on the next import the new highlight will be imported.

The reference-id is used like this: [[@name-of-the-note#^pn2xitti]]

---
title: "{{title | safe}}"
aliases:
{#- Backwards compatible with older version, which had @title in the published url -#}
{% set tempAlias = ["%40", citekey] | join | safe -%}
- "{{ tempAlias }}"
{% if shortTitle %}- {{shortTitle | safe}}
{% endif -%}
Year: {{date | format("YYYY")}}
tags: type/source
Authors: {{authors}}{{directors}}
permalink: "{{citekey | safe }}"
---
{#- These can be changed -#}
{#- This is the order in which the annotations are ordered -#}
{%-
set categoryHeading = {
"orange": "Main ideas and conclusions",
"yellow": "Ordinary notes",
"blue": "Quote / quotable",
"green": "Important To Me",
"red": "Disagree With Author",
"purple": "Interesting side-point",
"magenta": "Methodology",
"grey": "Definitions and concepts"
}
-%}
{%-
set categoryIcon = {
"orange": "💡",
"yellow": "📚",
"blue": "💬",
"green": "💚",
"red": "⛔",
"purple": "💭",
"magenta": "⚙️",
"grey": "🧩"
}
-%}
{#- ---------- Don't make any changes under here --------- #}
{%- macro minEditDate() -%}
{%- set tempDate = "" -%}
{%- for a in annotations -%}
{%- set testDate = a.date | format("YYYY-MM-DD#HH:mm:ss") -%}
{%- if testDate < tempDate or tempDate == ""-%}
{%- set tempDate = testDate -%}
{%- endif -%}
{%- endfor -%}
{%- for a in notes -%}
{%- set testDate = a.dateModified | format("YYYY-MM-DD#HH:mm:ss") -%}
{%- if testDate < tempDate or tempDate == ""-%}
{%- set tempDate = testDate -%}
{%- endif -%}
{%- endfor -%}
{{tempDate }}
{%- endmacro -%}
{# infer latest note date #}
{%- macro maxEditDate() -%}
{%- set tempDate = "" -%}
{%- for n in annotations -%}
{%- set testDate = n.date | format("YYYY-MM-DD#HH:mm:ss") -%}
{%- if testDate > tempDate or tempDate == ""-%}
{%- set tempDate = testDate -%}
{%- endif -%}
{%- endfor -%}
{%- for n in notes -%}
{%- set testDate = n.dateModified | format("YYYY-MM-DD#HH:mm:ss") -%}
{%- if testDate > tempDate or tempDate == ""-%}
{%- set tempDate = testDate -%}
{%- endif -%}
{%- endfor -%}
{{tempDate}}
{%- endmacro -%}
{#- handle | characters in zotero strings used in MD -#}
{% macro formatCell(cellText) -%}
{{ cellText | replace("|","❕")}}
{%- endmacro %}
{#- TAGS: handle space characters in zotero tags -#}
{%- set space = joiner(' ') -%}
{%- macro printTags(rawTags) -%}
{%- if rawTags.length > 0 -%}
{%- for tag in rawTags -%}
#{{ tag.tag | lower | replace(" ","_") }} {{ space() }}
{%- endfor -%}
{%- endif -%}
{%- endmacro %}
{%-
set zoteroColors = {
"#ff6666": "red",
"#f19837": "orange",
"#5fb236": "green",
"#ffd400": "yellow",
"#2ea8e5": "blue",
"#a28ae5": "purple",
"#e56eee": "magenta",
"#aaaaaa": "grey"
}
%}
# {{title}}
> [!info] Info - [**Zotero**]({{desktopURI}}) {% if DOI %}| [**DOI**](https://doi.org/{{DOI}}){% endif %} | Local {% for attachment in attachments | filterby("path", "endswith", ".pdf") %}[**PDF**](file:///{{attachment.path | replace(" ", "%20")}}){%- endfor %}
{% if ShortTitle %}> Short title: {{shortTitle | safe}}{% endif -%}
> Authors: {% for c in creators %}[[{{c.firstName}} {{c.lastName}}]] {% endfor %}
{% if publicationTitle %}> Publication: {{publicationTitle | safe}}{% endif -%}
> Type: {{itemType}}
> Year: {{date | format("YYYY")}}
> Zotero links: [Item]({{select}}) {% if pdfZoteroLink %}PDF: {{pdfZoteroLink}}{% endif %}
> Web links: {% if itemType == "webpage" %}[{{title}}]({{url}}){%else%}[Item]({{uri}}){%endif%} {% if pdfLink %}PDF: {{pdfLink}}{% endif %}
> {{printTags(note.tags)}}
>
> **History**
> Date item added to Zotero: [[{{dateAdded | format("YYYY-MM-DD")}}]]
{%- if annotations %}
> First date annotations or notes modified: [[{{minEditDate() | truncate(10,true,"")}}]]
> Last date annotations or notes modified: [[{{maxEditDate()| truncate(10,true,"")}}]]
{%- endif %}
> Export date: [[{{exportDate | format("YYYY-MM-DD")}}]]
{%- if relations.length > 0 %}
{{ "" }}
> [!abstract] Related Zotero items ({{ relations.length}}):
>
> | title | proxy note | desktopURI |
> | --- | --- | --- |
{%- for r in relations %}
> | {{formatCell(r.title)}} | [[@{{r.citekey}}]] | [Zotero Link]({{r.desktopURI}}) | {% if rel.DOI %}> DOI: {{rel.DOI}}{% endif %} |
{%- endfor -%}
{{ "" }}
{%- endif %}
{% if notes.length > 0 %}
> [!note] Notes ({{notes.length}})
{{ "" }}
{%- for note in notes -%}
{#- Clean up note, change heading level, just in case -#}
> {{ note.note | replace ("# ","### ") | replace(r/\n/g, '\n> ')}}
> {{printTags(note.tags)}}
> <small>📝️ (modified: {{ note.dateModified | format("YYYY-MM-DD") }}) [link](zotero://select/library/items/{{note.key}}) - [web]({{note.uri}})</small>
> {{ "" }}
> ---
{% endfor %}
{% endif -%}
> [!abstract]-
> {% if abstractNote %}
> {{abstractNote|replace("\n"," ")}}
> {% endif %}
---
## Persistant notes
{% persist "notes" %}
{% endpersist %}
---
## Annotations
{% for color, colorCategorie in zoteroColors %}
{%- for entry in annotations | filterby ("color", "startswith", color) -%}
{%- if entry.id %}
{% if entry and loop.first %}## {{categoryIcon[zoteroColors[entry.color]]}} {{categoryHeading[zoteroColors[color]]}}{% endif %}
{% set annoID = ["id-", entry.id] | join | lower %}
{%- persist annoID %}
{%- if entry.date > lastExportDate %}
{%- if entry.annotatedText %}{{categoryIcon[zoteroColors[entry.color]]}} {{ entry.annotatedText }}{% endif %}
{%- if entry.imageBaseName %}![[@{{citekey}}/{{entry.imageBaseName}}|300]]
{% endif %}
{{printTags(entry.tags)}}<small>([{{title | truncate(50)}} p.{{entry.pageLabel}}](zotero://open-pdf/library/items/{{entry.attachment.itemKey}}?page={{entry.page}}&annotation={{entry.id}})) edited:[[{{ entry.date | format("YYYY-MM-DD")}}]]</small>
{%- endif %}
{% endpersist %} {# do not add "-", entry-id needs newline #}
^{{ entry.id | lower }}
{%- if entry.comment %}
>[!note]
>{{entry.comment}}
{% endif -%}
{% endif -%} {# /if entry.id -#}
{% endfor -%}
{% endfor -%}
@mr-tazhibayev
Copy link

mr-tazhibayev commented Jan 8, 2025

It might be too late, but for those who still wonder how to fix that, (@ceciliechrstnsn), replace the code on the line 174.
Before:

{%- if entry.comment %}
>[!note] 
>{{entry.comment}}
{% endif -%}

After:

{%- if entry.comment %}
>[!note] 
>{{entry.comment | replace(r/\n/g, '\n> ') }}
{% endif -%}

@QWxleA thanks for the template! Really enjoy using it!

@rubidio2000
Copy link

Hi everyone,
I used external PDF editors on my iPad to markup my pdf's. Zotero has no problem with the interpretation of this annotations, as they show up in the app, but they don't import with this template.

Since different editors use different colors, would it be possible to insert a "default", or "other" color category which imports everything that is not annotated in one the current 8 colors?

I'm not a programmer of any kind and have been trying with ChatGPT, but it's not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment