diff --git a/layouts/partials/icon.html b/layouts/partials/icon.html
index 150dc929..0e1c1baf 100644
--- a/layouts/partials/icon.html
+++ b/layouts/partials/icon.html
@@ -1,6 +1,6 @@
-{{ $icon := resources.Get (print "icons/" . ".svg") }}
-{{ if $icon }}
+{{- $icon := resources.Get (print "icons/" . ".svg") -}}
+{{- if $icon -}}
- {{ $icon.Content | safeHTML }}
+ {{- $icon.Content | safeHTML -}}
-{{ end }}
+{{- end -}}
diff --git a/layouts/shortcodes/icon.html b/layouts/shortcodes/icon.html
index 7203424d..167806d9 100644
--- a/layouts/shortcodes/icon.html
+++ b/layouts/shortcodes/icon.html
@@ -1,8 +1,10 @@
-{{ $icon := resources.Get (printf "icons/%s.svg" ($.Get 0)) }}
-{{ if $icon }}
+{{- /* Avoid extra whitespace */ -}}
+{{- /* https://discourse.gohugo.io/t/55399/5 */ -}}
+{{- $icon := resources.Get (printf "icons/%s.svg" ($.Get 0)) -}}
+{{- if $icon -}}
- {{ $icon.Content | safeHTML }}
+ {{- strings.Replace $icon.Content "\n" "" | safeHTML -}}
-{{ else }}
- {{ errorf `[BLOWFISH] Shortcode "icon" error in "%s": Resource "%s" not found. Check the path is correct or remove the shortcode.` .Page.Path (printf "icons/%s.svg" ($.Get 0)) }}
-{{ end }}
+{{- else -}}
+ {{- errorf `icon shortcode: resource "%s" not found. Check the path is correct or remove the shortcode: %s` (printf "icons/%s.svg" ($.Get 0)) .Position -}}
+{{- end -}}