mgmeyers / obsidian-zotero-integration

Insert and import citations, bibliographies, notes, and PDF annotations from Zotero into Obsidian.
GNU General Public License v3.0
1.09k stars 55 forks source link

How do I access the "extras" field? #359

Open carljoseph opened 7 months ago

carljoseph commented 7 months ago

Hi BBT, the extras field is exported as an annotation. I want to include this text in my Obsidian template, but I can't figure out what variable to use?

Screenshot 2024-04-01 at 12 13 05 Screenshot 2024-04-01 at 12 13 26
carljoseph commented 7 months ago

Figured it out. {{extra}} works for me in my template.

msulwa commented 2 months ago

After a bit of tinkering and ChatGpt, what worked for me was to use regex to parse through the Extra field.

Take the following file as an example:

image

To extract the Read_Status, I apply the following set of scripts:

{%- set input_string = extra | string  | replace("\n", " ")%}
{%- set regex_read_status = r/Read_Status:\s*(.*?)(?=\s+\w+\s*:\s*|$)/g %}

{%- set matches_read_status = regex_read_status.exec(input_string) %}

{%- if matches_read_status and matches_read_status[1] %}
  {%- set read_status =matches_read_status[1] %}
  {{read_status}}
{%- endif %}

The output is:

Read

For more info on the regex applied, check out the following link: https://regex101.com/r/vB41So/2

For my use-case, I removed all spacing and line breaks and put a less readable version into my properties/frontmatter. The result is that when a template is applied the relevant field/s are updated.

For example (this is the same as the above template, without the additional spacing)

read_status: {% set input_string = extra | string  | replace("\n", " ")%}{% set regex_read_status = r/Read_Status:\s*(.*?)(?=\s+\w+\s*:\s*|$)/g %}{% set matches_read_status = regex_read_status.exec(input_string) %}{%- if matches_read_status and matches_read_status[1] %}  {%- set read_status =matches_read_status[1] %}{{read_status}}{%- endif %}

In the template, the nunjucks templating format might appear as an error, but the processed result works fine.

image