{{ $context := . }} {{ $defaults := dict "id" $context.Anchor }} {{ $max := 0 }} {{ $attrs := merge .Attributes $defaults }} {{ range $k, $v := .Page.Fragments.HeadingsMap }} {{ if gt $v.Level $max }} {{ $max = $v.Level }} {{ end }} {{ end }} {{ $level := $context.Level }} {{ if and $max (lt $max 6) }} {{ $level = add $context.Level (sub 6 $max) }} {{ end }} {{ .Text }}