Hugo stripping content of <p> tags


#1

Looking for some help with generating paragraph tags for content in my markdown file - I’ve read that this is a function of hugo to include multiple text blocks in <p> tags but not single ones, is there a way to overwrite that? I would like all my text blocks wrapped in <p> tags.

I saw similar issues on github and found the following code, only issue is that it ends up inserting empty ‘

’ tags into my content as well.

{{ $markdown := .Params.text_body | markdownify }}

{{ if not ( strings.Contains $markdown "<p>" ) }}
  <p>{{ $markdown }}</p>
  {{ else }}
  {{ $markdown }}
  {{ end }} 

#2

Do you have an example value for .Params.text_body ?


#3

In the markdown file - the text that isn’t getting formatted appears as so:

- template: block-text
  text_body: Eu consequat ac felis donec et odio pellentesque. Donec ac  odio tempor
  orci dapibus ultrices in iaculis. Dolor sit amet  consectetur adipiscing elit duis.

I’ve noticed that multiple blocks do get formatted as so:

- template: block-text
  text_body: |-
    ## Header 2

    In vitae turpis massa sed elementum tempus egestas. Condimentum vitae  sapien pellentesque habitant morbi tristique senectus et. Est lorem  ipsum dolor sit amet consectetur.

#4

Hmm yeah that’s odd. Like you said, the first params gets no <p> tags, and the second param gets only an opening <p> tag.

For reference, using your examples, this front matter:

---
text_body: |
  Eu consequat ac felis donec et odio pellentesque. Donec ac  odio tempor
  orci dapibus ultrices in iaculis. Dolor sit amet  consectetur adipiscing elit duis.
text_body_2: |
  ## Header 2

  In vitae turpis massa sed elementum tempus egestas. Condimentum vitae  sapien pellentesque habitant morbi tristique senectus et. Est lorem  ipsum dolor sit amet consectetur.
---

With this template:

{{ .Params.text_body | markdownify }}

{{ .Params.text_body_2 | markdownify }}

Gives me this output:

Eu consequat ac felis donec et odio pellentesque. Donec ac  odio tempor
orci dapibus ultrices in iaculis. Dolor sit amet  consectetur adipiscing elit duis.

<h2 id="header-2">Header 2</h2>

<p>In vitae turpis massa sed elementum tempus egestas. Condimentum vitae  sapien pellentesque habitant morbi tristique senectus et. Est lorem  ipsum dolor sit amet consectetur.