Search code examples
cssformattingmarkdownjekyllliquid

Iterate through lines in jekyll markdon


I have fetched a passage from a CSV data file in Jekyll via a markdown loop.

Now that I would like to display the lines as individual headings. Is there a way around

data = "this is the first line
this is the second line"

The above data variable when brought under markdown via code

#### {{data}}

What results is that the first line is brought under h4 and the second line is left out

<h4>this is the first line <br /></h4>
<p>this is the second line</p>

I would require the following though

<h4>this is the first line <br></h4>
<h4>this is the second line</h4>

Question Is there a workaround that brings individually split lines into distinct h4 tags.?


Solution

  • Is this what you want?

    <h4>{{ data | newlines_to_br }}</h4>
    

    It would result into:

    <h4>this is the first line<br>this is the second line</h4>