Search code examples
htmlmarkdownjekyllliquidkramdown

Jekyll Kramdown preserve new lines


I need to find a way to make Kramdown preserve new lines in jekyll posts which are writen in markdown

for example this text:

Hello
darkness
my
old
firend

is ouputed as:

<p>Hellodarknessmyoldfriend</p>

and I want it to be:

<p>Hello<br/>darkness<br/>my<br/>old<br/>friend</p>

How to config kramdown to do this ?


Solution

  • In Markdown a linebreak is added with a backslash (\) at the end of the line in question.

    Hello\
    darkness\
    my\
    old\
    friend
    

    Output:

    <p>Hello<br/>darkness<br/>my<br/>old<br/>friend</p>
    

    Per the official Kramdown docs, you need two backslashes, but I tested this in one of my projects and it works as listed above.

    If you're not trimming whitespace, you could use two spaces at the end of the line, but that's still something extra you'd need to add.

    If you are looking for a way to add nothing at the end and have a line-return create a <br> tag, there is no way to do this.