Trim newlines from .Inner in the 'code' shortcode

Closes #1437
This commit is contained in:
Joe Mooring 2021-04-30 12:11:34 -07:00 committed by Bjørn Erik Pedersen
parent 9117f54b39
commit fce835fead

View File

@ -5,21 +5,22 @@
{{ $codeLang = (index . 0 | strings.TrimPrefix ".") }} {{ $codeLang = (index . 0 | strings.TrimPrefix ".") }}
{{ end }} {{ end }}
{{ with .Get "codeLang" }}{{ $codeLang = . }}{{ end }} {{ with .Get "codeLang" }}{{ $codeLang = . }}{{ end }}
{{ if eq $codeLang "html"}} {{ if eq $codeLang "html" }}
{{ $codeLang = "go-html-template" }} {{ $codeLang = "go-html-template" }}
{{ end }} {{ end }}
<div class="code relative" id="{{ $file | urlize}}"> <div class="code relative" id="{{ $file | urlize }}">
{{- with $file -}} {{- with $file -}}
<div class="filename san-serif f6 dib lh-solid pl2 pv2">{{.}}</div> <div class="filename san-serif f6 dib lh-solid pl2 pv2">{{ . }}</div>
{{- end -}} {{- end -}}
{{ if ne (.Get "copy") "false" }} {{ if ne (.Get "copy") "false" }}
<button class="needs-js copy bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2" title="Copy this code to your clipboard." data-clipboard-action="copy" aria-label="copy button"> <button class="needs-js copy bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2" title="Copy this code to your clipboard." data-clipboard-action="copy" aria-label="copy button">
</button> </button>
{{/* 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 */}} {{/* 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}} {{ end }}
<div class="code-copy-content nt3" {{with .Get "download"}}id="{{.}}"{{end}}> <div class="code-copy-content nt3" {{ with .Get "download" }}id="{{ . }}"{{ end }}>
{{ if .Get "nocode" }}{{ $.Inner }}{{ else }}{{ with $codeLang }}{{- highlight $.Inner . "" | -}}{{ else }}<pre><code>{{- .Inner | string -}}</code></pre>{{ end }}{{ end }} {{ $inner := trim .Inner "\n" | safeHTML }}
{{ if .Get "nocode" }}{{ $inner }}{{ else }}{{ with $codeLang }}{{ highlight $inner . "" }}{{ else }}<pre><code>{{ $inner }}</code></pre>{{ end }}{{ end }}
</div> </div>
</div> </div>