Prevent Markdownify to strip first p tags

Just discovered this invented-here behavior of stripping <p> tags when the content is only one line. I have this line in my single.html template:

{{ .Content | markdownify }}

But when the content of an item has only one line, there is no <p> tag added, and the style of the single template breaks.

On closer inspection, I see that I am also guilty of using the no-paragraph markdownify, earlier in the same template:

<h1>{{ .Title | markdownify }}</h1>

Therefore, I’m voting for @fritzmg suggestion, moving the special paragraph-ignoring behavior-- this is an exception to the syntax published at https://www.markdownguide.org/ --to a new helper that strips paragraphs. My new template would look like this:

<h1>{{ .Title | markdownify | inline }}</h1>
{{ .Content | markdownify }}

Yes, it’ll necessitate refactoring of templates built for previous versions of Hugo. But that’s a side effect of the original mistake of inventing new behavior for something as ubiquitous as Markdown.

1 Like