A shortcode which allows one provide information which is hidden by default, if desired the user may expand it. This is useful to provide more detailed information which does not fit in a footnote or optional sections within the content. Readers which are interested may consume the extra content while other readers are not bothered by it.
This article was written for Hugo 0.74.
Usage
Add the hidden content in the expand shortcode and you’re done. By default the expander will be collapsed. Note this shortcode requires to use the %-syntax (see
this post for more info).
option
effect
optional
default
0
sets the title of the expander
yes
Expand
1
sets the expand icon
yes
↕
When starting with a heading the first content line must be blank; this can be considered a bug in Hugo. Also a blank line in markdown after the shortcode is required.
Example
{{% expand "Expand example" %}}
#### Example
Add any mark-up, shortcode or footnotes here
{{% /expand %}}
Example
Add any mark-up, shortcode or footnotes here
Code
The current CSS reserves the full space of the div even when not expanded. Hence you will have a lot of unwanted blank space at the end of the page. If you know how to resolve this please contact me.
The shortcode is fairly straight forward but looks more complicated due to the printf usage. For more info why print is required see
this post.
In CSS display: none; was explicitly avoided to hide the content because it might break some libraries when used within the expandable content, for example
mermaid.
For the tooltips the
tooltips CSS library is used.
The headings used within the expand shortcode will show in the table of content, to avoid this one can use the following shortcode to show heading instead:
License: The text and content is licensed under CC BY-NC-SA 4.0.
All source code I wrote on this page is licensed under The Unlicense; do as you please, I'm not liable nor provide warranty.
Noticed an error in this post? Corrections are
spam.appreciated.