summaryrefslogtreecommitdiff
path: root/layouts/_default/single.gmi
blob: 2ea32cd48604527551f67b5c8e86799e665fa4f2d9cef95ca0691cb0b443d831 (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
{{ 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 `(?s)(.*?)(?:(?:\n|^)\x60{3}.*?\n\x60{3}(?:\n|$)|$)` $content }}

{{- range $chunks }}
	{{- $before_chunk := (. | replaceRE `(?s)(.*?)(?:(?:(?:\n|^)\x60{3}.*?\n\x60{3}(?:\n|$))|$)` "$1") }}
	{{- $cur_chunk := $before_chunk }}

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

{{- $content | safeHTML }}
{{- $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 := $ref_val | replaceRE `\[(.+?)\]\((.+?)\)` "$1" }}
		{{- $ref_link := $ref_val | replaceRE `\[(.+?)\]\((.+?)\)` "$2" }}
{{ print "=> " $ref_link " " $emoji $ref_num ": " $ref_text | safeHTML }}
	{{- end }}
{{- end }}
{{- end }}