HUGO

How to retain newline newline with Innertext in shortcodes?

I am writing a shortcode which accepts text and prints in a certain format on the page e.g. changing text color for any text between chosen magic chars say #…# .

My shortcode works and looks great. But the problem is when I pass the text to the shortcode, it all wraps into one single line. I am looking for the following solution :

  1. The newline in the text between {{< shortcode >}} .. {{< /shortcode >}} should not be removed.
  2. I want to access each line passed to the shortcode individually so that I can process it in certain way, e.g. highlight first word of every line.

Maybe I was in a hurry not to realize that its not the shortcode problem, but the HTML. I need to either add <pre> or find some other way. Hence, my original quesiton is not valid. But maybe I will let it be there and add my work here to help the future visitors thinking around the same line.

Yes, Hugo does not remove anything in the .Inner block.

A related tip; we have since recently started to support raw string literals in shortcode params, so you can now also do:

{{< shortcode  text=`some long text

with newlines and **markdown**.` >}}

But I would say that in most cases, using .Inner is the most sensible thing.