List of posts does not render HTML in summary

I am trying to render a list of posts on my homepage showing only a summary. I would like to preserve the formatting of the summary and any links. However, all HTML is stripped from the summary. Code is below.

{{ define "main" }}
  {{ $pages := where site.RegularPages "Type" "posts" }}
    {{ range (.Paginate $pages).Pages }}
      <article class="post h-entry">
        <div class="title p-name">
          <h1>
            {{ .Title }}
         </h1>
       </div>
       <div class="content p-summary">
         {{ .Summary | safeHTML }}
           {{ if .Truncated }}
             <a href="{{ .RelPermalink }}">Read more</a>
           {{ end }}
      </div>
      {{ partial "articleInfo.html" . }}
    </article>
  {{ end }}
  {{ partial "pagination.html" . }}
{{ end }}

If I replace .Summary with .Content the full HTML is rendered even without the | safeHTML. I have also tried .Summary | markdownify but there is no difference. I think that I am misunderstanding the usage of safeHTML or possibly the scope of .Summary. Any help resolving this issue is appreciate.

Try inspecting it because unless there’s links and other HTML it’s should look plain

It depends on how you define the summary. See:
https://gohugo.io/content-management/summaries

Summary Definition Result
Automatic Summary Split Plain text
Manual Summary Split Markdown is rendered
Front Matter Summary Markdown is rendered
2 Likes

Thanks again Joe. I searched for hours and missed that page somehow.

Thank you for the input. I had inspected it. My concern was for posts that had embedded HTML which wasn’t rendered. Joe’s answer below solved the problem.

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