Hello!
I have a peculiar issue I’d like to get some opinions on and understand better how indents/spacing in Markdown/Hugo could have weird formatting output when rendered.
We have a shortcode include
which basically just takes in a file name and displays the .Content
of it. We use this shortcode a lot when displaying long code samples in our documentation. Furthermore, we have an expand
shortcode which creates a collapsible dropdown that uses the .Inner
function to show whatever content is in between the opening and closing tag. In our case, we use the include
shortcode in there to sometimes show/hide long code samples that has less precedence.
We’ve noticed in the latest versions of Hugo that the following issue has started with the code samples.
The above image shows a code sample in an include
shortcode that is being used in a list. When it is in a list, you can see the double spacing that’s occurring.
However, the same code sample outside of a list but still being imported by the include
shortcode is rendered properly.
The Markdown (first image is line 23, second image is line 25) shows how the shortcode is being handled differently when it’s in a list/indented versus when it is outside of one.
Even more weirdly, I’m trying to understand how indents/spacing seem to create unexpected behavior in the rendering output. For example:
In the above image, see how the include
shortcode is indented on line 36, and how line 39 has a spacing before/after the include
shortcode that’s nested inside the expand
. These two examples cause the same behavior of creating the double spacing in the couple sample.
However, line 44 and line 47, when the indentation and spacing are removed, the code samples render correctly with the single spacing expected output.
Is there something I’m missing in how indentation/spacing could be creating these unexpected rendering issues? Is this a known issue with Hugo?
Thanks for your time!
Edit: I’m using Hugo version 104.1. Also providing the code for the above mentioned shortcodes in case the issue is somehow related to them:
{{ $file := .Get "file" }}
<!-- get the title of the page where we're using the include -->
{{ $title := $.Page.File.BaseFileName }}
{{ $url := $.Page.RelPermalink }}
{{ if $file }}
<!-- if it exists, get the file and display the contents -->
{{ $page := .Site.GetPage $file }}
{{ with $page }}
{{ .Content }}
{{- else -}}
<!-- print to the terminal the include file and where it's being called that cannot be found -->
{{ warnf "INCLUDE_NOT_FOUND [%s include not found in file %s.md at path %s]" $file $title $url }}
{{- end -}}
{{ end }}`
Expand:
```<div class="expand">
<div class="expand-label" title="Expand" tabindex="0" aria-label="Expand" aria-expanded="true" style="cursor: pointer; margin-bottom: 1rem; color: #1e53a0;" onclick="$h = $(this);$h.next('div').slideToggle(100,function () {$h.children('i').attr('class',function () {return $h.next('div').is(':visible') ? 'fas fa-chevron-down' : 'fas fa-chevron-right';});});">
<i style="font-size:x-small;" class="fas fa-chevron-right"></i>
<span style="font-size: 1rem; font-weight: bold; margin-top: 1rem;">
{{ $expandMessage := T "Expand-title" }}
{{ if .IsNamedParams }}
{{ .Get "default" | default $expandMessage }}
{{ else }}
{{ .Get 0 | default $expandMessage }}
{{ end }}
</span>
</div>
<div class="expand-content" style="display: none; font-size: 1rem;">
{{ if eq .Page.File.Ext "md" }}
<span>
{{ .Inner }}
{{ else }}
<span>
{{ .Inner| htmlUnescape | safeHTML }}
</span>
{{ end }}
</div>
</div>`