blob: 38a2a8ce4590584be701e6ee0d165fc9d51437fa8e7603a2e053c966bc8cbe5d (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
{{ define "main" }}
{{ $emoji := cond (.Page.Params.showlinkemoji | default true) (emojify ":link: ") "" -}}
=> / {{ emojify ":link:" | safeHTML }} Return to homepage
{{ if (.Page.Params.pageinfo | default true) }}{{ partial "pageinfo.gmi" . }}
{{ end -}}
# {{ .Name | safeHTML }}
{{ $content := .RawContent }}
{{- $scratch := newScratch }}
{{- $chunks := findRESubmatch `(?sm)(?:(.*?)(^\x60{3}[^\x60].*?^\x60{3}$))|(.*$)` $content }}
{{- $ref_index := 0 }}
{{- range $chunks }}
{{- $before_pre := index . 1 }}
{{- $pre := index . 2 }}
{{- $after_pre := index . 3 }}
{{- $rendered_text := print $before_pre $after_pre }}
{{- if ($.Page.Params.makerefs | default true) }}
{{- $chunk_refs := findRESubmatch `!?\[(.+?)\]\((.+?)(?:\s+"(.+?)")?\)` $rendered_text }}
{{- $scratch.Add "refs" $chunk_refs }}
{{- range $chunk_refs }}
{{- $ref_index = add $ref_index 1 }}
{{- $ref_text := index . 1 }}
{{- $rendered_text = replace $rendered_text (index . 0) (print $ref_text "[" $ref_index "]") 1 }}
{{- end }}
{{- else }}
{{- $rendered_text = $rendered_text | replaceRE `(?m)^!?\[(.+?)\]\((.+?)(?:\s+"(.+?)")?\)$` (print "=> $2 " $emoji "$1") }}
{{- end }}
{{- $rendered_text = $rendered_text | replaceRE `(?m)^####{1,3}` "###" }}
{{- $rendered_text = $rendered_text | replaceRE `\*{3}(\S|\S.*?\S)\*{3}` "$1" }}
{{- $rendered_text = $rendered_text | replaceRE `\*{2}(\S|\S.*?\S)\*{2}` "$1" }}
{{- $rendered_text = $rendered_text | replaceRE `\*{1}(\S|\S.*?\S)\*{1}` "$1" }}
{{- $rendered_text = $rendered_text | replaceRE `(?m)^[-+] ` "* " }}
{{- $rendered_text = $rendered_text | emojify }}
{{- if $before_pre }}
{{- $rendered_text | safeHTML }}
{{- $pre | safeHTML }}
{{- else }}
{{- $pre | safeHTML }}
{{- $rendered_text | safeHTML }}
{{- end }}
{{- end }}
{{- $refs := $scratch.Get "refs" }}
{{- if and (.Page.Params.makerefs | default true) $refs }}
{{- $ref_index := 0 }}
## Links
{{- range $refs }}
{{- $ref_index = add $ref_index 1 }}
{{- $ref_text := index . 1 }}
{{- $ref_link := index . 2 }}
{{- $ref_title := index . 3 }}
{{ print "=> " $ref_link (emojify " :link: ") $ref_index ": " (cond (ne (len $ref_title) 0) $ref_title $ref_text) | safeHTML }}
{{- end }}
{{- end }}
{{- end }}
|