summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--layouts/_default/single.gmi36
2 files changed, 24 insertions, 13 deletions
diff --git a/TODO b/TODO
index 07d01a6..607b9e4 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
- fix spacing
- add tag support
- document "layouts/_default/single.gmi"
-- fix "layouts/_default/single.gmi" changing preformatted text
- test internationalization
diff --git a/layouts/_default/single.gmi b/layouts/_default/single.gmi
index 09456ab..8695a9b 100644
--- a/layouts/_default/single.gmi
+++ b/layouts/_default/single.gmi
@@ -8,21 +8,33 @@
{{ end -}}
# {{ .Name | safeHTML }}
{{ $content := .RawContent }}
-{{- $refs := findRE `\[.+?\]\(.+?\)` $content }}
-{{- if (.Page.Params.makerefs | default true) }}
- {{- range $ref_index, $ref_val := $refs }}
- {{- $ref_num := add $ref_index 1 }}
- {{- $ref_text := $ref_val | replaceRE `\[(.+?)\]\((.+?)\)` "$1" }}
- {{- $content = replace $content $ref_val (print $ref_text "[" $ref_num "]") 1 }}
+{{- $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 }}
-{{- else }}
- {{- $content = $content | replaceRE `(?m)\[(.+?)\]\((.+?)\)` (print "=> $2 " $emoji "$1") }}
+ {{- $cur_chunk = $cur_chunk | replaceRE `(?m)^####{1,3}` "###" }}
+ {{- $cur_chunk = $cur_chunk | replaceRE `(?s)\*{3}(.*?)\*{3}|\*{2}(.*?)\*{2}|\*{1}(.*?)\*{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 = $content | replaceRE `(?m)^####{1,3}` "###" }}
-{{- $content = $content | replaceRE `(?s)\*{3}(.*?)\*{3}|\*{2}(.*?)\*{2}|\*{1}(.*?)\*{1}` "$1$2$3" }}
-{{- $content = $content | replaceRE `(?m)^- ` "* " }}
-{{- $content = $content | emojify }}
+
{{- $content | safeHTML }}
+{{- $refs := $scratch.Get "refs" }}
{{- if and (.Page.Params.makerefs | default true) $refs }}
## Links