In my front matter I have variables like so:
about_me: |
*Hi* there!
This is an [example](/home/).
I have the following goal:
- Include
about_me
into my Hugo template, - And put it into a paragraph (
<p>
) tag.
Sounds simple enough! But not so in reality.
Markdownify example
This works fine when the front matter variable has two paragraphs:
{{ .Params.about_me | markdownify }}
<p><em>Hi</em> there!</p>
<p>This is an <a href="/home/">example</a>.</p>
But what if the front matter variable has a single paragraph?
about_me: |
*Hi* there! This is an [example](/home/).
<em>Hi</em> there! This is an <a href="/home/">example</a>.
No paragraph tag! So let’s add one:
<p>{{ .Params.about_me | markdownify }}</p>
The output with a single paragraph is now:
<p><em>Hi</em> there! This is an <a href="/home/">example</a>.</p>
It works!
But what if the front matter variable has multiple paragraphs?
about_me: |
*Hi* there!
This is an [example](/home/).
Now we get:
<p><p><em>Hi</em> there!</p> <p>This is an <a href="/home/">example</a>.</p> </p>
And there we have it, the erroneous <p>
and </p>
tag.
>> How do I prevent this from happening? What’s the 2020-approach of handling these situations?
RenderString perhaps?
Unfortunately, .RenderString
suffers from the same problem.
Hugo Static Site Generator v0.69.2-EC9DCF30 windows/amd64 BuildDate: 2020-04-24T07:51:17Z
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.14.1"