diff options
author | Nicholas Johnson <nick@nicholasjohnson.ch> | 2023-01-22 00:00:00 +0000 |
---|---|---|
committer | Nicholas Johnson <nick@nicholasjohnson.ch> | 2023-01-22 00:00:00 +0000 |
commit | de7644ed839b70cb6ed6480d363d6a88336b39150dcc923ab9a475d59c008913 (patch) | |
tree | 484eee38333185c3a84c722c7b442e04ae98b2321707bceb0c2d1ef4e3ce5127 | |
parent | b073e35b942de7cdf78abde8f7bbd1439f37d8220412ad9a3907f9da0e6c93a7 (diff) | |
download | hugo-theme-journal-0.2.0.tar.gz hugo-theme-journal-0.2.0.zip |
Render files in chunks to ignore preformatted textv0.2.0
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | layouts/_default/single.gmi | 36 |
2 files changed, 24 insertions, 13 deletions
@@ -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 |