blob: 7c110ee1d24bdb2cd81699b0759b780e248832122c6660e23289dfe199182792 (
plain)
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
|
{{ define "main" }}
{{ $emoji := cond (.Page.Params.showlinkemoji | default true) (emojify ":link: ") "" -}}
=> / {{ emojify ":link:" }} Return to homepage
{{ if (.Page.Params.pageinfo | default true) }}{{ partial "pageinfo" . }}
{{ end -}}
# {{ .Name | safeHTML }}
{{ $content := .RawContent }}
{{- $content = $content | replaceRE `\n####{0,3}` "\n###" }}
{{- $scratch := newScratch }}
{{- $scratch.Set "ref" 1 }}
{{- $refs := findRE `\[.+?\]\(.+?\)` $content }}
{{- $scratch.Set "content" $content }}
{{- if (.Page.Params.makerefs | default true) }}
{{- range $refs }}
{{- $ref := $scratch.Get "ref" }}
{{- $contentInLoop := $scratch.Get "content" }}
{{- $url := (printf "%s #%d" . $ref) }}
{{- $contentInLoop := replace $contentInLoop . $url }}
{{- $scratch.Set "content" $contentInLoop }}
{{- $scratch.Set "ref" (add $ref 1) }}
{{- end }}
{{- $content = $scratch.Get "content" | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` "$1[$3]" }}
{{- else }}
{{- $content = $content | replaceRE `\n\[(.+?)\]\((.+?)\)` (print "\n=> $2 " $emoji "$1") }}
{{- end }}
{{- $content = $content | replaceRE `\*{3}(.+?)\*{3}|\*{2}(.+?)\*{2}|\*{1}(.+?)\*{1}` "$1$2$3$4$5$6" }}
{{- $content = $content | replaceRE `\n- ` "\n* " }}
{{- $content = $content | emojify }}
{{- $content | safeHTML }}
{{- if and (.Page.Params.makerefs | default true) $refs }}
## Links
{{- $scratch.Set "ref" 1 }}
{{- range $refs }}
{{- $ref := $scratch.Get "ref" }}
{{- $url := (printf "%s #%d" . $ref) }}
{{ $url | replaceRE `\[(.+?)\]\((.+?)\) #(\d+)` (print "=> $2 " $emoji "$3: $1") | safeHTML }}
{{- $scratch.Set "ref" (add $ref 1) }}
{{- end }}
{{- end }}
{{- end }}
|