summaryrefslogtreecommitdiff
path: root/layouts/_default/single.gmi
blob: e93ee8183a37f9ebc6a181640cf24f2a41a80365542ffceb36f5a0fe5c336760 (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
{{ 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 }}
{{- $scratch := newScratch }}
{{- $chunks := findRE `(?sm)(?:(.*?)(^\x60{3}[^\x60].*?^\x60{3}$))|(.*$)` $content }}

{{- range $chunks }}
	{{- $before_pre := replaceRE `(?sm)(?:(.*?)(^\x60{3}[^\x60].*?^\x60{3}$))|(.*$)` "$1" . 1 }}
	{{- $pre        := replaceRE `(?sm)(?:(.*?)(^\x60{3}[^\x60].*?^\x60{3}$))|(.*$)` "$2" . 1 }}
	{{- $after_pre  := replaceRE `(?sm)(?:(.*?)(^\x60{3}[^\x60].*?^\x60{3}$))|(.*$)` "$3" . 1 }}

	{{- $rendered_text := print $before_pre $after_pre }}

	{{- $scratch.Set "refs" (findRE `\[.+?\]\(.+?\)` $rendered_text) }}
	{{- $refs := $scratch.Get "refs" }}
	{{- if ($.Page.Params.makerefs | default true) }}
		{{- range $ref_index, $ref_val := $refs }}
			{{- $ref_num := add $ref_index 1 }}
			{{- $ref_text := replaceRE `\[(.+?)\]\((.+?)\)` "$1" $ref_val 1 }}
			{{- $rendered_text = replace $rendered_text $ref_val (print $ref_text "[" $ref_num "]") 1 }}
		{{- end }}
	{{- else }}
		{{- $rendered_text = $rendered_text | replaceRE `(?m)^\[(.+?)\]\((.+?)\)$` (print "=> $2 " $emoji "$1") }}
	{{- end }}
	{{- $rendered_text = $rendered_text | replaceRE `(?m)^####{1,3}` "###" }}
	{{- $rendered_text = $rendered_text | replaceRE `\*{3}(\S.+?\S)\*{3}|\*{2}(\S.+?\S)\*{2}|\*{1}(\S.+?\S)\*{1}` "$1$2$3" }}
	{{- $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 }}

## Links
	{{- range $ref_index, $ref_val := $refs }}
		{{- $ref_num := add $ref_index 1 }}
		{{- $ref_text := replaceRE `\[(.+?)\]\((.+?)\)` "$1" $ref_val 1 }}
		{{- $ref_link := replaceRE `\[(.+?)\]\((.+?)\)` "$2" $ref_val 1 }}
{{ print "=> " $ref_link (emojify " :link: ") $ref_num ": " $ref_text | safeHTML }}
	{{- end }}
{{- end }}
{{- end }}