Prevent <!--more--> from wrapping .Content in p tags?

I’ve noticed that the <!--more--> tag in the .Content causes the content to be wrapped in p tags. For example:

Raw content:
My awesome content <!--more--> is really awesome.

This causes .Content to be rendered as:
<p>My awesome content </p><p> is really awesome.</p>

Is there anyway to cause <!--more--> to just be invisible (have no visual effect) in .Content?

Hi @Peter_Olds. So I think your scenario is an edge case, as folks usually put the <!--more--> between paragraphs, not in them.

But you could work around this by manually stripping out that piece

{{ $content := replace .RawContent "<!--more-->" "" | markdownify }}
{{ $content }}

Brilliant! My usecase is indeed odd, I use <!--more--> very much as visual thing vs content thing. Your snippet worked great.

Actually, interestingly enough, | markdownify causes shortcodes to not render.

Another option is to use findRE and replace the first x number of paragraph tag occurrences in .Content with whatever you choose

Thanks for the continued suggestions. I haven’t been able to find a way to only replace n instances of the string. It looks like the replace implementation always replaces all instances of the string. It’d be nice if we could do something similar to findRE and do replace INPUT OLD NEW NUM.

Additionally, it seems findRE just returns the string it found and not the position and <!--more--> is implemented as </p>(.|\n\n)<p>. This is the same behavior as how paragraphs are implemented on the Markdown side making <!--more--> match all other paragraphs in .Content.

I think this just points me towards the fact my use case is truly unique and I should probably rethink my use case haha.

I just found a super hacky way of accomplishing what I’m looking for and sharing (even though I’m embarrassed at the level of the hack):

{{ $more := findRE "</p>(.|\n\n)<p>" .Content 1 }}
{{ $one := index $more 0 }}
{{ $split := split $.Page.Content $one }}
{{ $scratch := newScratch }}
{{ $scratch.Set "didMore" 0 }}
{{ if gt (len $split) 1 }}
    {{ range $split }}
        {{ . | safeHTML }}
        {{ if eq ($scratch.Get "didMore") 1 }}
            {{ $one | safeHTML }}
        {{ else }}
            {{ $scratch.Set "didMore" 1 }}
        {{ end }}
    {{ end }}
{{ else }}
    {{ (index $split 0) | safeHTML }}
{{ end }}

It checks if there are more than one </p>\n\n<p> blocks in the content, if there are not it prints it directly. If there are it writes each to | safeHTML and appends </p>\n\n<p> except for the first.

Edit: It’s certainly not perfect, the following scenario will still break it, but I can live with it:

My content.

This is <!--more--> cool!

This would generate:

<p>My content. This is </p>\n\n<p>cool!</p>

Thanks, got the same issue :beers: