From 33ed9bbd32bdac7586140d8a31465761d3065bf5 Mon Sep 17 00:00:00 2001 From: Razon Yang Date: Sat, 9 Dec 2023 01:56:30 +0800 Subject: [PATCH] feat(config-toggle): allow wrapping code with delimiters (#96) --- layouts/partials/bootstrap/config-toggle.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/layouts/partials/bootstrap/config-toggle.html b/layouts/partials/bootstrap/config-toggle.html index 6bbd41d..5fc7aa6 100644 --- a/layouts/partials/bootstrap/config-toggle.html +++ b/layouts/partials/bootstrap/config-toggle.html @@ -3,12 +3,14 @@ {{- $style := "tabs" }} {{- $fill := false }} {{- $title := "" }} +{{- $delimiter := false }} {{- if .IsNamedParams }} {{- with .Get "filename" }}{{ $filename = . }}{{ end }} {{- with .Get "langs" }}{{ $langs = split . "," }}{{ end }} {{- with .Get "style" }}{{ $style = . }}{{ end }} {{- with .Get "fill" }}{{ $fill = . }}{{ end }} {{- with .Get "title" }}{{ $title = . }}{{ end }} + {{- with .Get "delimiter" }}{{ $delimiter = . }}{{ end }} {{- else }} {{- with .Get 0 }}{{ $filename = . }}{{ end }} {{- with .Get 1 }}{{ $langs = split . "," }}{{ end }} @@ -46,9 +48,17 @@
{{- $src := $.Inner | htmlUnescape | transform.Unmarshal }} {{- range $i, $lang := $langs -}} + {{- $lang = lower $lang }} {{- $id := printf "code-toggle-%s-%s" $idPrefix $lang -}} {{- $code := $src | transform.Remarshal $lang -}} {{- $code = replaceRE "\n+" "\n" $code -}} + {{- if $delimiter }} + {{- if eq $lang "toml" }} + {{- $code = printf "+++\n%s+++\n" $code }} + {{- else if eq $lang "yaml" }} + {{- $code = printf "---\n%s---\n" $code }} + {{- end }} + {{- end }}