{{ $page := . }} {{ $result := $page.Content }} {{ $matches := findRESubmatch "]" $result }} {{ with $matches }} {{ $max := 0 }} {{ range . }} {{ $level := index . 1 | int }} {{ if gt $level $max }} {{ $max = $level }} {{ end }} {{ end }} {{ if and $max (lt $max 6) }} {{ $shift := sub 6 $max }} {{ range seq $max | collections.Reverse }} {{ $old := . }} {{ $new := add $old $shift }} {{ $result = replaceRE (printf "])" $old) (printf "" $old) (printf "" $new) $result }} {{ end }} {{ end }} {{ end }} {{ return $result }}