Continuing the discussion from Flag indicating manual vs auto summary generation:

I would like to be able to have a tag to start the summary, just like <!--more--> ends it. I suggest <!--start-sum-->.

I described my issue and why I think this being a good idea in that support request: (https://discuss.gohugo.io/t/set-summary-completely-manually/6737). (I don’t know how to link to a topic that’s already opened.)

I ended up with this problem today and this is how I solve it.

I insert TOC in markdown at the beginning of my post and want to filter that out from the .Summary.

So I put a comment called <!--endtoc--> at the end of that TOC and filter that TOC out using this snippet:

{{ $summary_splits := split .Summary "<!--endtoc-->" }}
{{ if eq (len $summary_splits) 2 }}
    <!-- If that endtoc special comment is present, output only the part after that comment as Summary. -->
    {{ index $summary_splits 1 | safeHTML }}
{{ else }}
    <!-- Print the whole Summary if endtoc special comment is not found. -->
    {{ .Summary }}
{{ end }}