summaryrefslogtreecommitdiff
path: root/layouts/_default
diff options
context:
space:
mode:
authorNicholas Johnson <nick@nicholasjohnson.ch>2023-03-16 00:00:00 +0000
committerNicholas Johnson <nick@nicholasjohnson.ch>2023-03-16 00:00:00 +0000
commit4f0a41cd22ee5c44f750a974b7203f6f33e4e5609b317ca43941666f66b8fade (patch)
tree1343fe9748c5a518ab15a3e302569dadd8b23c1558d2c70e3af269d042df28b5 /layouts/_default
parent5300afb80be0bd166e2ac0a3c53039302615e627a4061f47bc5b8881ba27e07a (diff)
downloadhugo-theme-journal-4f0a41cd22ee5c44f750a974b7203f6f33e4e5609b317ca43941666f66b8fade.tar.gz
hugo-theme-journal-4f0a41cd22ee5c44f750a974b7203f6f33e4e5609b317ca43941666f66b8fade.zip
Fix link parsing in single Gemini pagesv0.4.4
Gemini pages would forget about links coming before preformatted text, causing improper link indexing and missing links.
Diffstat (limited to 'layouts/_default')
-rw-r--r--layouts/_default/single.gmi24
1 files changed, 13 insertions, 11 deletions
diff --git a/layouts/_default/single.gmi b/layouts/_default/single.gmi
index d164f8e..df0ff26 100644
--- a/layouts/_default/single.gmi
+++ b/layouts/_default/single.gmi
@@ -10,6 +10,7 @@
{{ $content := .RawContent }}
{{- $scratch := newScratch }}
{{- $chunks := findRE `(?sm)(?:(.*?)(^\x60{3}[^\x60].*?^\x60{3}$))|(.*$)` $content }}
+{{- $ref_index := 0 }}
{{- range $chunks }}
{{- $before_pre := replaceRE `(?sm)(?:(.*?)(^\x60{3}[^\x60].*?^\x60{3}$))|(.*$)` "$1" . 1 }}
@@ -18,13 +19,13 @@
{{- $rendered_text := print $before_pre $after_pre }}
- {{- $scratch.Set "refs" (findRE `\[.+?\]\(.+?\)` $rendered_text) }}
- {{- $refs := $scratch.Get "refs" }}
+ {{- $chunk_refs := findRE `\[.+?\]\(.+?\)` $rendered_text }}
+ {{- $scratch.Add "refs" $chunk_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 }}
+ {{- range $chunk_refs }}
+ {{- $ref_index = add $ref_index 1 }}
+ {{- $ref_text := replaceRE `\[(.+?)\]\((.+?)\)` "$1" . 1 }}
+ {{- $rendered_text = replace $rendered_text . (print $ref_text "[" $ref_index "]") 1 }}
{{- end }}
{{- else }}
{{- $rendered_text = $rendered_text | replaceRE `(?m)^\[(.+?)\]\((.+?)\)$` (print "=> $2 " $emoji "$1") }}
@@ -47,13 +48,14 @@
{{- $refs := $scratch.Get "refs" }}
{{- if and (.Page.Params.makerefs | default true) $refs }}
+{{- $ref_index := 0 }}
## 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 }}
+ {{- range $refs }}
+ {{- $ref_index = add $ref_index 1 }}
+ {{- $ref_text := replaceRE `\[(.+?)\]\((.+?)\)` "$1" . 1 }}
+ {{- $ref_link := replaceRE `\[(.+?)\]\((.+?)\)` "$2" . 1 }}
+{{ print "=> " $ref_link (emojify " :link: ") $ref_index ": " $ref_text | safeHTML }}
{{- end }}
{{- end }}
{{- end }}