-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathapi-ref-link-all-partial.html
More file actions
47 lines (41 loc) · 1.88 KB
/
api-ref-link-all-partial.html
File metadata and controls
47 lines (41 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{{ $context := .context}}
{{ $paragraph := .paragraph}}
{{ $jsonPath := printf "versioned_docs/%s/links.json" (partial "version.html" (dict "context" $context)).dirpath }}
{{ if fileExists $jsonPath }}
{{ with getJSON $jsonPath }}
{{ $links := . }}
{{ range $name, $data := $links }}
{{ if and $data.path (ne $data.path "") }}
{{ $path := $data.path }}
{{ $kind := $data.kind }}
{{/* I don't think there is any other way to include literal backtick inside a raw-string */}}
{{/* The regex captures $name that is surrounded by any of */}}
{{/* [$name] `name`*/}}
{{/* Hugo doesn't support lookahead/lookbehind, so
the groups have to be used to match correctly*/}}
{{ $pattern := "" }}
{{ if strings.Contains $name "_" }}
{{ $pattern = printf `([\[%s ])(%s)([\]%s. ])` "`" $name "`"}}
{{/* If name contains "_" use more lenient regex, which allows the name
to be surrounded by whitespace. This is required, otherwise names like "load"
are matched in random places */}}
{{ else }}
{{ $pattern = printf `([\[%s])(%s)([\]%s])` "`" $name "`" }}
{{ end }}
{{ $matches := findRE $name $paragraph}}
{{ if gt (len $matches) 0 }}
{{ $a_html := (printf "$1<a href=\"%s/\">%s</a>$3" $path $name) }}
{{ $paragraph = replaceRE $pattern $a_html $paragraph | safeHTML}}
{{ end }}
{{ end }}
{{ end }}
{{/* Remove backticks around links */}}
{{ $leadingBacktickRemovalPattern := "`<a" }}
{{ $trailingBacktickRemovalPattern := "</a>`" }}
{{ $paragraph = replaceRE $leadingBacktickRemovalPattern "<a" $paragraph}}
{{ $paragraph = replaceRE $trailingBacktickRemovalPattern "</a>" $paragraph}}
{{ $paragraph | safeHTML }}
{{ end }}
{{ else }}
Missing links.json for this version!
{{ end }}