Remove empty paragraph tags from string

.content | $.Page.RenderString

I’m rendering a string from my markdown file to generate some content and I’m encountering the occasional empty p tag <p></p>

Currently I’m using CSS to set the display to none for an empty p tag

p:empty {
display:none;
}

I’ve tried a few things but I can’t figure out if I can remove before I output the HTML as I’d like to clean it up that way if possible. Any suggestions would be great, thanks

{{ .content | $.Page.RenderString | replaceRE `<p>\s*</p>` "" | safeHTML }}
4 Likes

Very useful, thank you.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.