Markdownify dosn't add paragraph html tag on string input

Hey

I have created this example to show what my issue is, notice the \n's:

"content": {
  "text1": "Liquorice cake cake jelly jelly beans. Candy oat cake oat cake oat cake sesame snaps. Croissant cotton candy carrot cake cake brownie wafer chupa chups chocolate.",
  "text2": "Liquorice cake cake jelly jelly beans.\n\nCandy oat cake oat cake oat cake sesame snaps. Croissant cotton candy carrot cake cake brownie wafer chupa chups chocolate."
}

{{ with .content.text1 }}
    <div class="c-content">
        {{ . | markdownify  }}
    </div>
{{ end }}

{{ with .content.text2 }}
    <div class="c-content">
        {{ . | markdownify  }}
    </div>
{{ end }}

The problem is that text1 isn’t getting <p></p> around it’s text as each paragraph in text2 is.

In this example it’s easy enough just to add the <p></p> in the layout, but the idea is that there is only one text field, and some times is just formatted as text1 and other times like text2 (with linebreaks).

I havn’t been able to find a proper solution, and i’m not sure if there is a config for Blackfriday that could be set to consider a single string as a paragraph too.

Hope anyone can help.

It’s a known issue, and there are workarounds and other discussions around the web and here, one place to start: Markdownify and paragraphs.

I did manage to find that issue on github, but noticed it was closed without specifying exactly what the fix was - Hence why i asked about what i could do. I guess i can only create a new issue, or comment on that old closed one.

The workaround that people are showing doesn’t really work, as manually wrapping things in <p> is really tedious. But thanks for responding, hoped it was fixed :frowning:

I hadn’t had this specific issue, and don’t recall all the details as this has come up before. I mentally marked it as a “Blackfriday” thing, which more active members of our community take over to that project’s issue queue, and then it gets fixed in an update.

I imagine this issue is an edge case in that many folks don’t check nor care the p elements are being omitted. Here’s hoping it gets noticed and fixed! :slight_smile:

This is what I always use:

  {{ if in (string .Inner) "\n\n" }}
    {{ .Inner | markdownify }}
  {{ else }}
    <p>{{ .Inner | markdownify }}</p>
  {{ end }}
3 Likes

Yeah looks like that is a workaround, but in the end it’s a workaround that shouldn’t be necessary IMO. But thank you for sharing - I will use that and hope the GitHub issue will get traction.