-
- {{- range seq (sub $firstHeaderLevel $largest) -}}
-
- + {{- $header | safeHTML -}} + {{- else -}} +
- + {{- $header | safeHTML -}} + {{- end -}} + {{- end -}} + + {{- $firstHeaderLevel := $largest }} + {{- $lastHeaderLevel := len (seq (index (findRE "[1-6]" (index $headers (sub (len $headers) 1)) 1) 0)) -}} + + {{- range seq (sub $lastHeaderLevel $firstHeaderLevel) -}} + {{- if in ($.Scratch.Get "bareul") (add . $firstHeaderLevel) -}} +
- - {{- $header | safeHTML -}} - {{- else -}} -
- - {{- $header | safeHTML -}} - {{- end -}} - {{- end -}} - - {{- $firstHeaderLevel := $largest }} - {{- $lastHeaderLevel := len (seq (index (findRE "[1-6]" (index $headers (sub (len $headers) 1)) 1) 0)) -}} - - {{- range seq (sub $lastHeaderLevel $firstHeaderLevel) -}} - {{- if in ($.Scratch.Get "bareul") (add . $firstHeaderLevel) -}} - -{{- else -}} - - -{{- end -}} -{{- end -}} - -{{- end -}} + {{- end -}} + {{- end -}} + + {{- end -}} +
-
- {{- $.Scratch.Add "bareul" (sub (add $largest .) 1) -}}
- {{- end -}}
- {{- range $i, $header := $headers -}}
- {{- $headerLevel := index (findRE "[1-6]" . 1) 0 -}}
- {{- $headerLevel := len (seq $headerLevel) -}}
-
- {{/* get id="xyz" */}}
- {{- $id := index (findRE "(id=\"(.*?)\")" $header 9) 0 }}
-
- {{- /* strip id="" to leave xyz, no way to get regex capturing groups in hugo */ -}}
- {{- $cleanedID := replace (replace $id "id=\"" "") "\"" "" }}
- {{- $header := replaceRE "
-
- {{/* the first should not be recorded */}}
- {{- if ne $prevHeaderLevel . -}}
- {{- $.Scratch.Add "bareul" . -}}
+
+
\ No newline at end of file
+
+
+
+
+ {{- i18n "toc" | default "Table of Contents" }}
+
+
+ {{- $headers := findRE "(.|\n])+? " .Content -}}
+ {{- $has_headers := ge (len $headers) 1 -}}
+ {{- if $has_headers -}}
+
+ {{- $largest := 6 -}}
+ {{- range $headers -}}
+ {{- $headerLevel := index (findRE "[1-6]" . 1) 0 -}}
+ {{- $headerLevel := len (seq $headerLevel) -}}
+ {{- if lt $headerLevel $largest -}}
+ {{- $largest = $headerLevel -}}
{{- end -}}
{{- end -}}
+
+ {{- $firstHeaderLevel := len (seq (index (findRE "[1-6]" (index $headers 0) 1) 0)) -}}
+
+ {{- $.Scratch.Set "bareul" slice -}}
+
+ -
+ {{- range seq (sub $firstHeaderLevel $largest) -}}
+
-
+ {{- $.Scratch.Add "bareul" (sub (add $largest .) 1) -}}
+ {{- end -}}
+ {{- range $i, $header := $headers -}}
+ {{- $headerLevel := index (findRE "[1-6]" . 1) 0 -}}
+ {{- $headerLevel := len (seq $headerLevel) -}}
+
+ {{/* get id="xyz" */}}
+ {{- $id := index (findRE "(id=\"(.*?)\")" $header 9) 0 }}
+
+ {{- /* strip id="" to leave xyz, no way to get regex capturing groups in hugo */ -}}
+ {{- $cleanedID := replace (replace $id "id=\"" "") "\"" "" }}
+ {{- $header := replaceRE "
-
+ {{/* the first should not be recorded */}}
+ {{- if ne $prevHeaderLevel . -}}
+ {{- $.Scratch.Add "bareul" . -}}
+ {{- end -}}
+ {{- end -}}
+ {{- else -}}
+
+ {{- if lt $headerLevel $prevHeaderLevel -}}
+ {{- range seq (sub $prevHeaderLevel 1) -1 $headerLevel -}}
+ {{- if in ($.Scratch.Get "bareul") . -}}
+