I have a citation shortcode that (simplified) looks like this:
<cite
{{ with .Params.cite }}cite="{{ . }}"{{ end }}
itemscope
itemprop="citation"
itemtype="https://schema.org/
{{- with .Params.schemaType -}}
{{- . -}}
{{- else -}}
CreativeWork
{{- end -}}"
>
<span itemprop="name">{{- .Params.title | safeHTML -}}</span>{{- with 1 -}}{{- end -}}
</cite>
{{- with .Params.href -}}
</a>
{{- end -}}
However, if I don’t include that {{- with 1 -}}{{- end -}}
on the fifth-to-last line, the resulting HTML will have a space inserted after the <span>
(e.g., <cite ...><span ...>Foo</span> </cite>
). There is definitely no errant whitespace character at the end of the line in the shortcode.
I had a similar issue with the render hook for links. The example given in the docs is:
<a href="{{ .Destination | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
However, unless I add some whitespace removal to the start and end of the template, I ended up with additional spaces being added around every Markdown link. My resulting render hook looks like:
{{- with 1 -}}{{- end -}}<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noreferrer noopener"{{ end }}>{{ .Text | safeHTML }}</a>{{- with 1 -}}{{- end -}}
I’ve also used {{- $foo := 0 -}}
before.
Is this an issue to be reported, or expected behaviour? Is there some better way of removing unwanted whitespace (e.g., {{-}}
, though that is invalid syntax) than a no-op statement?