{{ $headers := findRE "(.|\n])+?" .Content }} {{ if ge (len $headers) 1 }}
{{ $h1_n := len (findRE "(.|\n])+?" .Content) }} {{ $re := (cond (eq $h1_n 0) "- {{ i18n "toc_title" }} - {{ $scratch := newScratch }} {{ $scratch.Set "prev_heading" 1 }}
    {{ range $headers }} {{ $header := . }} {{ range first 1 (findRE $re $header 1) }} {{ range findRE $renum . 1 }} {{ $next_heading := (cond (eq $h1_n 0) (sub (int .) 1 ) (int . ) ) }} {{ $prev_heading := $scratch.Get "prev_heading"}} {{ if lt $next_heading $prev_heading }} {{ range seq (sub $prev_heading $next_heading) }}
{{ end }} {{ end }} {{ if gt $next_heading $prev_heading }} {{ range seq (sub $next_heading $prev_heading) }}
{{ end }}