Editor-induced bugs
While working on this site, I suddenly noticed that an extra space was added after any link, but it was only visible when that link was followed by another character like a parenthesis.
I dug hard and on a hunch, found that it was caused by my recent addition of a render hook for links. I had simply followed the instructions and added the following snippet in layouts/_default/_markup/render-link.html
:
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
Eventually, I found this Hugo bug that enlightened me: turns out some text editors automatically add a newline at the end of the file on save to comply with the POSIX standard definition of a line (source).
This other StackOverflow thread lists some Gedit bugs where devs don’t want to add at least a GUI option to enable/disable the automatic addition of newline (the option now exists in gsettings), nor to simply display it… Some more discussion of this issue on Hugo Forums.
The Hugo-specific solution was to add a Go template snippet at the end of the render hooks which removes trailing newlines (credit):
diff --git a/layouts/_default/_markup/render-link.html b/layouts/_default/_markup/render-link.html
index f04b2e3bda072e15cf8ac7787e37e68744a76048..06727fbe334a084ad29a29a85caf8f3a4fd55bda 100644
--- a/layouts/_default/_markup/render-link.html
+++ b/layouts/_default/_markup/render-link.html
@@ -1 +1,2 @@
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
+{{- /* This comment removes trailing newlines. */ -}}
Information technology is such a complex interaction of countless moving parts, that I often wonder how it can work and produce any results at all!