{{- /* Annotated tree from a fenced text block. Two spaces per level; "# note" after a name; "@slug" at the end of a note links a specification. */ -}} {{- $rows := slice -}} {{- range split .Inner "\n" -}} {{- $line := strings.TrimRight " \t\r" . -}} {{- if and $line (not (hasPrefix (trim $line " ") "```")) -}} {{- $text := strings.TrimLeft " " $line -}} {{- $depth := div (sub (len $line) (len $text)) 2 -}} {{- $name := $text }}{{ $note := "" }}{{ $slug := "" -}} {{- with findRESubmatch `^(.+?)\s+#\s?(.*)$` $text 1 }}{{ $name = index (index . 0) 1 }}{{ $note = index (index . 0) 2 }}{{ end -}} {{- with findRESubmatch `^(.*?)\s*@([a-z0-9-]+)$` $note 1 }}{{ $note = index (index . 0) 1 }}{{ $slug = index (index . 0) 2 }}{{ end -}} {{- $rows = $rows | append (dict "depth" $depth "name" $name "note" $note "slug" $slug) -}} {{- end -}} {{- end -}}
{{ with .Get 0 }}
Layout{{ . }}
{{ end }}