hugo icon indicating copy to clipboard operation
hugo copied to clipboard

.TableOfContents generate "hahahugoshortcode" text if {{< icon >}} on ## level headers

Open divinerites opened this issue 6 years ago • 16 comments

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>


divinerites avatar Jul 09 '19 09:07 divinerites

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?

divinerites avatar Jul 09 '19 09:07 divinerites

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.

stale[bot] avatar Nov 11 '19 09:11 stale[bot]

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 avatar Nov 16 '19 04:11 plinss

@plinss's solution works well for icons. But using true shortcodes with separate

subhashb avatar Jan 24 '20 00:01 subhashb

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.

stale[bot] avatar May 23 '20 21:05 stale[bot]

You want to use the {{% delimiter in titles.

bep avatar May 23 '20 22:05 bep

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.

rodrigoalcarazdelaosa avatar Jun 15 '20 20:06 rodrigoalcarazdelaosa

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.

rodrigoalcarazdelaosa avatar Jun 25 '20 09:06 rodrigoalcarazdelaosa

This is still happening for me with Hugo 0.73.0.

Also happening with Hugo 0.74.3

rodrigoalcarazdelaosa avatar Jul 26 '20 08:07 rodrigoalcarazdelaosa

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.

bep avatar Jul 26 '20 14:07 bep

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: image

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

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!

rodrigoalcarazdelaosa avatar Jul 26 '20 15:07 rodrigoalcarazdelaosa

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.

stale[bot] avatar Dec 25 '20 12:12 stale[bot]

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:

image

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

image

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!

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!

rodrigoalcarazdelaosa avatar Dec 25 '20 17:12 rodrigoalcarazdelaosa

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:

image

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

image

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!

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!

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).

rodrigoalcarazdelaosa avatar Jan 05 '21 14:01 rodrigoalcarazdelaosa

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.

ncw avatar Jul 07 '21 17:07 ncw

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.

github-actions[bot] avatar Jul 08 '22 02:07 github-actions[bot]

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.

github-actions[bot] avatar Sep 24 '22 02:09 github-actions[bot]