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 }}