{{ $file := (.Get "file") }} {{ $content := readFile $file }} {{ $first_line_contains := (.Get "first_line_contains") }} {{ $last_line_contains := (.Get "last_line_contains") }} {{ $last_line_equals := (.Get "last_line_equals") }} {{ $show_line := false }} {{/*if true, first or last line was not found*/}} {{ $first_line_found := false}} {{ $last_line_found := false}} {{ $padding_after := (.Get "padding_after" | default "0" | int) }} {{ $first_line_num := 0 }} {{ $last_line_num := 0 }} {{ $linkFile := $file }} {{ $repo := "watermill" }} {{ if in $file "src-link/watermill-" }} {{ $repo = index (findRE "watermill-[a-z]+" $linkFile) 0 }} {{ $linkFile = replace $linkFile $repo "" }} {{ $linkFile = replace $linkFile "src-link//" "" }} {{ else if in $linkFile "src-link/" }} {{ $linkFile = replace $linkFile "src-link/" "" }} {{ else }} {{ $linkFile = print "docs/content/" $linkFile }} {{ end }} {{ $lines := slice }} {{ range $elem_key, $elem_val := split $content "\n" }} {{ $line_num := (add $elem_key 1) }} {{ if and (not $first_line_found) (in $elem_val $first_line_contains) }} {{ if ne $elem_key 0 }} {{ $lines = $lines | append "// ..." }} {{ end }} {{ $show_line = true }} {{ $first_line_found = true}} {{ $first_line_num = $line_num }} {{ end }} {{ if $show_line }} {{ $lines = $lines | append $elem_val }} {{ end }} {{ if and ($first_line_found) (in $elem_val $last_line_contains) (ne $last_line_contains "") }} {{ $last_line_found = true }} {{ end }} {{ if and ($first_line_found) (eq $elem_val $last_line_equals) (ne $last_line_equals "") }} {{ $last_line_found = true }} {{ end }} {{ if and $last_line_found $show_line }} {{ if gt $padding_after 0 }} {{ $padding_after = sub $padding_after 1}} {{ else }} {{ $lines = $lines | append "// ..." }} {{ $show_line = false }} {{ $last_line_num = $line_num }} {{ end }} {{ end }} {{ end }} Full source: [github.com/ThreeDotsLabs/{{ $repo }}/{{ $linkFile }}](https://github.com/ThreeDotsLabs/{{ $repo }}/tree/master/{{ $linkFile }}{{ if ne $first_line_num 0 }}#L{{ $first_line_num }}{{ end }}) {{ highlight (delimit $lines "\n") (.Get "type" | default "go") "" }} {{if not $first_line_found }} {{ errorf "`first_line_contains` %s not found in %s snippet" $first_line_contains $file }} {{end}} {{if and (not $last_line_found) (ne $last_line_contains "") }} {{ errorf "`last_line_contains` %s not found in %s snippet" $last_line_contains $file }} {{end}}