tera
tera copied to clipboard
Cannot use join to join with newlines
Expected behaviour
The join filter can be used to join an array of strings with newline characters.
Actual behaviour
The literal characters \n (as in \ followed by n) are placed in the string, rather than newlines.
This is quite unexpected, especially since split works just fine when given "\n".
Steps to reproduce
This is easily demonstrated with a shortcode:
{% set text = body | split("\n") | slice(start=1, end=-1) | join(sep="\n") %}
<pre>{{ text }}</pre>
Other information
I found this while using version 0.14.1 of zola.
Worth noting that this can be worked around with inputting a literal newline in the source, e.g.:
{% set text = body | split("\n") | slice(start=1, end=-1) | join(sep="
") %}
<pre>{{ text }}</pre>
Just seems strange that input to split can handle escaped characters, and join cannot. 🤷♂️