hugo
hugo copied to clipboard
.TableOfContents generate "hahahugoshortcode" text if {{< icon >}} on ## level headers
Hello,
My {{ .TableOfContents }} works flawlessly. But when I decided to add some icon on my headers, the markdown parsing produced a funny result with hahahugoshortcode text 😸 :
from source markdown :
## {{< icon name="fa-battery-1" >}} My title with icon
my text 1
### My title without icon
my text 2
produce this HTML
<nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#hahahugoshortcode-s0-hbhb-my-title-with-icon">HAHAHUGOSHORTCODE-s0-HBHB My title with icon</a>
<ul>
<li><a href="#my-title-without-icon">My title without icon</a></li>
</ul></li>
Ah ... may be this is already known, I finally found a reference on this Bep's post & on #1010
In this case, I guess that removing purely the icon/shortcode when rendering (instead of producing the hahaha text) would be a good compromise. But do not know if it would be acceptable or feasible?
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
I found the fix for this, use the {{% %}} syntax for the shortcodes. e.g.
## {{% icon name="fa-battery-1" %}} My title with icon
That will cause the shortcodes to be rendered before being passed to the markdown processor (which generates the .TableOfContent variable)
(requires Hugo 0.55+)
@plinss's solution works well for icons. But using true shortcodes with separate
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
You want to use the {{% delimiter in titles.
You want to use the
{{%delimiter in titles.
Is this confirmed to work with Hugo 0.72.0? I'm testing it and the icon shows in the first line of the body of the text, not in the title.
You want to use the
{{%delimiter in titles.Is this confirmed to work with Hugo 0.72.0? I'm testing it and the icon shows in the first line of the body of the text, not in the title.
This is still happening for me with Hugo 0.73.0.
This is still happening for me with Hugo 0.73.0.
Also happening with Hugo 0.74.3
Note that any fix for this issue would be to issue some kind of warning/error instead of the haha... placeholder. The proper tix is what I say above. If you see some other issues related to this, that is something different.
Note that any fix for this issue would be to issue some kind of warning/error instead of the haha... placeholder. The proper tix is what I say above. If you see some other issues related to this, that is something different.
I'm using Wowchemy, which implements this shortcode to render icons. I copy the code below:
{{- if (.Get "name") -}}
{{- $icon := .Get "name" -}}
{{- $pack := or (.Get "pack") "fas" -}}
{{- $pack_prefix := $pack -}}
{{- if in (slice "fab" "fas" "far" "fal") $pack -}}
{{- $pack_prefix = "fa" -}}
{{- end -}}
{{- $padding_right := (.Get "padding_right") | default 1 -}}{{/* Defaulting to 1 prevents no spacing when minimizing HTML. */}}
<i class="{{ $pack }} {{ $pack_prefix }}-{{ $icon }} {{with (.Get "padding_left")}}pl-{{.}}{{end}} {{with $padding_right}}pr-{{.}}{{end}} {{if ne (.Get "fixed_width") "false"}}fa-fw{{end}}"></i>
{{- end -}}
If I use the shortcode with this syntax {{< >}} I see the icon on the header but the HAHAHUGOSHORTCODE text on the ToC, like this:

If I use the {{% %}} syntax then the icon is rendered on the next line below the header, like this:

I reported this issue on wowchemy-hugo-modules and was referred here, but the solution posted here doesn't work for me. I'm also mentioning @gcushen (creator of Wowchemy) just in case.
Thanks for your time!
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
Note that any fix for this issue would be to issue some kind of warning/error instead of the haha... placeholder. The proper tix is what I say above. If you see some other issues related to this, that is something different.
I'm using Wowchemy, which implements this shortcode to render icons. I copy the code below:
{{- if (.Get "name") -}} {{- $icon := .Get "name" -}} {{- $pack := or (.Get "pack") "fas" -}} {{- $pack_prefix := $pack -}} {{- if in (slice "fab" "fas" "far" "fal") $pack -}} {{- $pack_prefix = "fa" -}} {{- end -}} {{- $padding_right := (.Get "padding_right") | default 1 -}}{{/* Defaulting to 1 prevents no spacing when minimizing HTML. */}} <i class="{{ $pack }} {{ $pack_prefix }}-{{ $icon }} {{with (.Get "padding_left")}}pl-{{.}}{{end}} {{with $padding_right}}pr-{{.}}{{end}} {{if ne (.Get "fixed_width") "false"}}fa-fw{{end}}"></i> {{- end -}}If I use the shortcode with this syntax
{{< >}}I see the icon on the header but the HAHAHUGOSHORTCODE text on the ToC, like this:
If I use the
{{% %}}syntax then the icon is rendered on the next line below the header, like this:
I reported this issue on
wowchemy-hugo-modulesand was referred here, but the solution posted here doesn't work for me. I'm also mentioning @gcushen (creator of Wowchemy) just in case.Thanks for your time!
Just wanted to remind this. The proposed solution doesn't work for me as the icon is not rendered on the heading but on the next line below. Maybe it's not a Hugo issue but a Wowchemy issue (related to the above icon shortcode). It'd be great if @gcushen could confirm it. Thanks in advance!
Note that any fix for this issue would be to issue some kind of warning/error instead of the haha... placeholder. The proper tix is what I say above. If you see some other issues related to this, that is something different.
I'm using Wowchemy, which implements this shortcode to render icons. I copy the code below:
{{- if (.Get "name") -}} {{- $icon := .Get "name" -}} {{- $pack := or (.Get "pack") "fas" -}} {{- $pack_prefix := $pack -}} {{- if in (slice "fab" "fas" "far" "fal") $pack -}} {{- $pack_prefix = "fa" -}} {{- end -}} {{- $padding_right := (.Get "padding_right") | default 1 -}}{{/* Defaulting to 1 prevents no spacing when minimizing HTML. */}} <i class="{{ $pack }} {{ $pack_prefix }}-{{ $icon }} {{with (.Get "padding_left")}}pl-{{.}}{{end}} {{with $padding_right}}pr-{{.}}{{end}} {{if ne (.Get "fixed_width") "false"}}fa-fw{{end}}"></i> {{- end -}}If I use the shortcode with this syntax
{{< >}}I see the icon on the header but the HAHAHUGOSHORTCODE text on the ToC, like this:
If I use the
{{% %}}syntax then the icon is rendered on the next line below the header, like this:
I reported this issue on
wowchemy-hugo-modulesand was referred here, but the solution posted here doesn't work for me. I'm also mentioning @gcushen (creator of Wowchemy) just in case.Thanks for your time!
Just wanted to remind this. The proposed solution doesn't work for me as the icon is not rendered on the heading but on the next line below. Maybe it's not a Hugo issue but a Wowchemy issue (related to the above
iconshortcode). It'd be great if @gcushen could confirm it. Thanks in advance!
For anyone curious I got around this by directly including the icons without using any shortcode, just using the <i class="fab fa-linux"></i> syntax (in the case of Font Awesome icons).
I've come across this problem too.
I'll just note that the {{% %}} syntax doesn't work if you have renderer.unsafe = false and neither does the plain <i class="fab fa-linux"></i> solution for the same reason.
It would be nice to fix the table of contents renderer so ignores shortcodes.
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.