{{ $url := (printf "%s#%s" .Page.Permalink .Anchor) | safeURL }}
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
<a class="heading-anchor" href="{{ $url }}">
{{ .Text | safeHTML }}
</a>
</h{{ .Level }}>