From fce835feade31eb120461d2690ef7185c511364d Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 30 Apr 2021 12:11:34 -0700 Subject: [PATCH] Trim newlines from .Inner in the 'code' shortcode Closes #1437 --- layouts/shortcodes/code.html | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/layouts/shortcodes/code.html b/layouts/shortcodes/code.html index eafc02e6b..0ee25149d 100644 --- a/layouts/shortcodes/code.html +++ b/layouts/shortcodes/code.html @@ -1,25 +1,26 @@ {{ $file := .Get "file" }} {{ $codeLang := "" }} {{ $suffix := findRE "(\\.[^.]+)$" $file 1 }} -{{ with $suffix }} +{{ with $suffix }} {{ $codeLang = (index . 0 | strings.TrimPrefix ".") }} {{ end }} {{ with .Get "codeLang" }}{{ $codeLang = . }}{{ end }} -{{ if eq $codeLang "html"}} +{{ if eq $codeLang "html" }} {{ $codeLang = "go-html-template" }} {{ end }} -
+
{{- with $file -}} -
{{.}}
+
{{ . }}
{{- end -}} {{ if ne (.Get "copy") "false" }} {{/* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}} - {{end}} -
- {{ if .Get "nocode" }}{{ $.Inner }}{{ else }}{{ with $codeLang }}{{- highlight $.Inner . "" | -}}{{ else }}
{{- .Inner | string -}}
{{ end }}{{ end }} + {{ end }} +
+ {{ $inner := trim .Inner "\n" | safeHTML }} + {{ if .Get "nocode" }}{{ $inner }}{{ else }}{{ with $codeLang }}{{ highlight $inner . "" }}{{ else }}
{{ $inner }}
{{ end }}{{ end }}