tera icon indicating copy to clipboard operation
tera copied to clipboard

Cannot use join to join with newlines

Open acheronfail opened this issue 4 years ago • 1 comments

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.

acheronfail avatar Aug 29 '21 10:08 acheronfail

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. 🤷‍♂️

acheronfail avatar Aug 29 '21 11:08 acheronfail