Zotero Integration - Template - why all the new lines in markdown document?

Hi all,

I have adapted the following template to create Literature Notes from Zotero references. I am using Zotero Integration, BetterBibtex and Zotfile plugins.

---
title: {{title | safe}}
authors: {{authors}}
year: {{date | format("YYYY")}}
type: {{itemType}}
permalink: "{{citekey | safe }}"
---
**Title:** {{title | safe}}
**Author(s):** {{authors}}
**Year:** {{date | format("YYYY")}}
**Type:** {{itemType}}
**Zotero Item:** [Link to Item]({{select}}) 
**Zotero Document** {{pdfZoteroLink}} 

>[!citation]-
>{{bibliography}}

---

### Annotations
*Exported: {{exportDate | format("YYYY-MM-DD h:mm a")}}*

{% for annotation in annotations %}
{% if annotation.annotatedText %} "{{annotation.annotatedText}}" [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}) <mark style="background-color: {{annotation.color}};color: black">Comment</mark> 
{% endif %}

{% if annotation.comment %} "{{annotation.comment}}" [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}) <mark style="background-color: {{annotation.color}};color: black">Comment</mark>
{% endif %}

{% if annotation.imageRelativePath %} ![[{{annotation.imageRelativePath}}]] [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}) <mark style="background-color: {{annotation.color}};color: black">Image</mark>
{% endif %}
{% endfor %}

---

Why does the resulting markdown file (as in the plain text file opened in any program), look like the following with large and increasing numbers of new lines between the annotations, comments and images brought across (random article and annotations used for illustration)?

---
title: An Architecture for Active Networking
authors: Samrat Bhattacharjee, Kenneth L. Calvert, Ellen W. Zegura
year: 1997
type: bookSection
permalink: "bhattacharjeeArchitectureActiveNetworking1997"
---
**Title:** An Architecture for Active Networking
**Author(s):** Samrat Bhattacharjee, Kenneth L. Calvert, Ellen W. Zegura
**Year:** 1997
**Type:** bookSection
**Zotero Item:** [Link to Item](zotero://select/library/items/TQPLAK5L) 
**Zotero Document** [Bhattacharjee et al_1997_An Architecture for Active Networking.pdf](zotero://select/library/items/ZJBPCVV8) 

>[!citation]-
>Bhattacharjee, S., Calvert, K. L., & Zegura, E. W. (1997). An Architecture for Active Networking. In A. Tantawy (Ed.), _High Performance Networking VII: IFIP TC6 Seventh International Conference on High Performance Networks (HPN ‘97), 28th April – 2nd May 1997, White Plains, New York, USA_ (pp. 265–279). Springer US. [https://doi.org/10.1007/978-0-387-35279-4_17](https://doi.org/10.1007/978-0-387-35279-4_17)

---

### Annotations
*Exported: 2023-09-17 10:14 am*


 "Active networking offers a change in the usual network paradigm: from passive carrier of bits to a more general computation engine. The implementation of such a change is likely to enable radical new applications that cannot be foreseen today. Large-scale deployment, however, involves significant challenges in interoperability, security, and scalability. In this paper we define an active networking architecture in which users control the invocation of pre-defined, network-based functions through control information in packet headers." [Page 1](zotero://open-pdf/library/items/ZJBPCVV8?page=1) <mark style="background-color: #ffd400;color: black">Comment</mark> 






 "The network consists of switching nodes, which are connected via links. In this simple model, nodes don't do anything except process the packets received on their incoming links; processing an incoming packet may result in one or more packets being transmitted on outgoing links." [Page 2](zotero://open-pdf/library/items/ZJBPCVV8?page=2) <mark style="background-color: #2ea8e5;color: black">Comment</mark> 










 ![[Attachments/bhattacharjeeArchitectureActiveNetworking1997/image-7-x75-y327.png]] [Page 7](zotero://open-pdf/library/items/ZJBPCVV8?page=7) <mark style="background-color: #ffd400;color: black">Image</mark>



---

%% Import Date: 2023-09-17T10:14:58.568+10:00 %%

It looks fine in markdown view of course as all of the extra new lines are ignored. But I want the actual text file to have good formatting as well without loads of random white space.

Is there a way to control the way new lines are added here? I can’t seem to figure out why differing (but increasing) numbers of new lines are being added between items here.

Thanks so much for any guidance!

Yes, try adjusting the whitespace control while previewing the template in Data explorer (found in the Command palette).

Amazing, thanks so much for your help. Was not aware of data explorer or the whitespace control - powerful stuff. But I still have a few niggling issues.

So here is where the template is now:

---
title: {{title | safe}}
authors: {{authors}}
year: {{date | format("YYYY")}}
type: {{itemType}}
permalink: "{{citekey | safe }}"
---
**Title:** {{title | safe}}
**Author(s):** {{authors}}
**Year:** {{date | format("YYYY")}}
**Type:** {{itemType}}
**Zotero Item:** [Link to Item]({{select}}) 
**Zotero Document** {{pdfZoteroLink}} 

>[!citation]-
>{{bibliography}}

---

### Annotations
*Exported: {{exportDate | format("YYYY-MM-DD h:mm a")}}*

{% for annotation in annotations -%}
{%- if annotation.annotatedText -%} "{{-annotation.annotatedText-}}" [Page {{-annotation.page-}}](zotero://open-pdf/library/items/{{-annotation.attachment.itemKey-}}?page={{-annotation.page-}}) <mark style="background-color: {{annotation.color}};color: black">Comment</mark> 
{%- endif -%}

{%- if annotation.comment -%} "{{-annotation.comment-}}" [Page {{-annotation.page-}}](zotero://open-pdf/library/items/{{-annotation.attachment.itemKey-}}?page={{-annotation.page-}}) <mark style="background-color: {{annotation.color}};color: black">Comment</mark>
{%- endif %}

{% if annotation.imageRelativePath -%} ![[{{-annotation.imageRelativePath-}}]] [Page {{-annotation.page-}}](zotero://open-pdf/library/items/{{-annotation.attachment.itemKey-}}?page={{-annotation.page-}}) <mark style="background-color: {{annotation.color}};color: black">Image</mark>
{%- endif -%}
{%- endfor %}

---

And the result:

---
title: An Architecture for Active Networking
authors: Samrat Bhattacharjee, Kenneth L. Calvert, Ellen W. Zegura
year: 1997
type: bookSection
permalink: "bhattacharjeeArchitectureActiveNetworking1997"
---
**Title:** An Architecture for Active Networking
**Author(s):** Samrat Bhattacharjee, Kenneth L. Calvert, Ellen W. Zegura
**Year:** 1997
**Type:** bookSection
**Zotero Item:** [Link to Item](zotero://select/library/items/TQPLAK5L) 
**Zotero Document** [Bhattacharjee et al_1997_An Architecture for Active Networking.pdf](zotero://select/library/items/ZJBPCVV8) 

>[!citation]-
>Bhattacharjee, S., Calvert, K. L., & Zegura, E. W. (1997). An Architecture for Active Networking. In A. Tantawy (Ed.), _High Performance Networking VII: IFIP TC6 Seventh International Conference on High Performance Networks (HPN ‘97), 28th April – 2nd May 1997, White Plains, New York, USA_ (pp. 265–279). Springer US. [https://doi.org/10.1007/978-0-387-35279-4_17](https://doi.org/10.1007/978-0-387-35279-4_17)

---

### Annotations
*Exported: 2023-09-17 9:09 pm*

"Active networking offers a change in the usual network paradigm: from passive carrier of bits to a more general computation engine. The implementation of such a change is likely to enable radical new applications that cannot be foreseen today. Large-scale deployment, however, involves significant challenges in interoperability, security, and scalability. In this paper we define an active networking architecture in which users control the invocation of pre-defined, network-based functions through control information in packet headers." [Page1](zotero://open-pdf/library/items/ZJBPCVV8?page=1) <mark style="background-color: #ffd400;color: black">Comment</mark>

"The network consists of switching nodes, which are connected via links. In this simple model, nodes don't do anything except process the packets received on their incoming links; processing an incoming packet may result in one or more packets being transmitted on outgoing links." [Page2](zotero://open-pdf/library/items/ZJBPCVV8?page=2) <mark style="background-color: #2ea8e5;color: black">Comment</mark>



![[Attachments/bhattacharjeeArchitectureActiveNetworking1997/image-7-x75-y327.png]] [Page7](zotero://open-pdf/library/items/ZJBPCVV8?page=7) <mark style="background-color: #ffd400;color: black">Image</mark>

---

%% Import Date: 2023-09-17T21:09:22.291+10:00 %%

I have managed to resolve many of the whitespace issues with your advice, but the final image attachment has a bunch of whte space before it which I can’t seem to remove. Any ideas?

Thanks.

Try adding an ending - to the preceding `{%- endif %}.

Thank you - I have tried that and every other combination of adding or removing the - but there is still one final space that won’t disappear between the second last and last item.

Perhaps it has something to do with the if statement logic. If there is no Comment or Image as t parses the if statements, will it put a blank line? That is, how does t handle the output when the current annotation being pulled in the For loop is not one of the ohter two categories?

Worked it out - don’t ask me why the following code works but it does! I will mark this comment as the solution so others might find the final working code, but huge thanks to Feralflora for pointing me to whitespace control and data explorer (see rest of thread for details).

---
title: {{title | safe}}
authors: {{authors}}
year: {{date | format("YYYY")}}
type: {{itemType}}
permalink: "{{citekey | safe }}"
---
**Title:** {{title | safe}}
**Author(s):** {{authors}}
**Year:** {{date | format("YYYY")}}
**Type:** {{itemType}}
**Zotero Item:** [Link to Item]({{select}}) 
**Zotero Document** {{pdfZoteroLink}} 

>[!citation]-
>{{bibliography}}

---

### Annotations
*Exported: {{exportDate | format("YYYY-MM-DD h:mm a")}}*
{% for annotation in annotations %}
{% if annotation.annotatedText -%} "{{annotation.annotatedText}}" [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}) <mark style="background-color: {{annotation.color}};color: black">Comment</mark>
{% endif -%}
{% if annotation.comment -%} "{{annotation.comment}}" [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}) <mark style="background-color: {{annotation.color}};color: black">Comment</mark>
{% endif -%} {% if annotation.imageRelativePath %}![[{{annotation.imageRelativePath}}]] [Page {{annotation.page}}](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.page}}) <mark style="background-color: {{annotation.color}};color: black">Image</mark>
{% endif %} {% endfor %}
---

Produces the following:

---
title: An Architecture for Active Networking
authors: Samrat Bhattacharjee, Kenneth L. Calvert, Ellen W. Zegura
year: 1997
type: bookSection
permalink: "bhattacharjeeArchitectureActiveNetworking1997"
---
**Title:** An Architecture for Active Networking
**Author(s):** Samrat Bhattacharjee, Kenneth L. Calvert, Ellen W. Zegura
**Year:** 1997
**Type:** bookSection
**Zotero Item:** [Link to Item](zotero://select/library/items/TQPLAK5L) 
**Zotero Document** [Bhattacharjee et al_1997_An Architecture for Active Networking.pdf](zotero://select/library/items/ZJBPCVV8) 

>[!citation]-
>Bhattacharjee, S., Calvert, K. L., & Zegura, E. W. (1997). An Architecture for Active Networking. In A. Tantawy (Ed.), _High Performance Networking VII: IFIP TC6 Seventh International Conference on High Performance Networks (HPN ‘97), 28th April – 2nd May 1997, White Plains, New York, USA_ (pp. 265–279). Springer US. [https://doi.org/10.1007/978-0-387-35279-4_17](https://doi.org/10.1007/978-0-387-35279-4_17)

---

### Annotations
*Exported: 2023-09-17 10:40 pm*

"Active networking offers a change in the usual network paradigm: from passive carrier of bits to a more general computation engine. The implementation of such a change is likely to enable radical new applications that cannot be foreseen today. Large-scale deployment, however, involves significant challenges in interoperability, security, and scalability. In this paper we define an active networking architecture in which users control the invocation of pre-defined, network-based functions through control information in packet headers." [Page 1](zotero://open-pdf/library/items/ZJBPCVV8?page=1) <mark style="background-color: #ffd400;color: black">Comment</mark>
 
"This is my comment" [Page 1](zotero://open-pdf/library/items/ZJBPCVV8?page=1) <mark style="background-color: #ffd400;color: black">Comment</mark>
 
![[Attachments/bhattacharjeeArchitectureActiveNetworking1997/image-1-x43-y258.png]] [Page 1](zotero://open-pdf/library/items/ZJBPCVV8?page=1) <mark style="background-color: #ffd400;color: black">Image</mark>
 
"The network consists of switching nodes, which are connected via links. In this simple model, nodes don't do anything except process the packets received on their incoming links; processing an incoming packet may result in one or more packets being transmitted on outgoing links." [Page 2](zotero://open-pdf/library/items/ZJBPCVV8?page=2) <mark style="background-color: #2ea8e5;color: black">Comment</mark>
 
![[Attachments/bhattacharjeeArchitectureActiveNetworking1997/image-7-x23-y480.png]] [Page 7](zotero://open-pdf/library/items/ZJBPCVV8?page=7) <mark style="background-color: #ff6666;color: black">Image</mark>
 
---

%% Import Date: 2023-09-17T22:40:58.825+10:00 %%

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.