Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`replace` and `replaceRE` don't work in shortcode anymore #7095

Closed
Jos512 opened this issue Mar 26, 2020 · 2 comments
Closed

`replace` and `replaceRE` don't work in shortcode anymore #7095

Jos512 opened this issue Mar 26, 2020 · 2 comments

Comments

@Jos512
Copy link

@Jos512 Jos512 commented Mar 26, 2020

As reported on the forum and confirmed there by another user, string functions like replace and replaceRE don't work in shortcodes anymore.

This page template code works:

{{ replace .TableOfContents "TableOfContents" "toc" | safeHTML }}

Creating the shortcode equivalent doesn't perform the replacement operation:

{{ replace .Page.TableOfContents "TableOfContents" "toc" | safeHTML }}

The issue happens when I call the shortcode with {{<toc>}} and with {{%toc%}}.

What version of Hugo are you using (hugo version)?

Hugo Static Site Generator v0.68.3/extended windows/amd64 BuildDate: unknown
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.14.1"

Does this issue reproduce with the latest release?

Yes.

Since when does the issue happen?

The problem started with Hugo 0.55. The issue wasn't present with the version before that, Hugo 0.54.

Is there an example site to replicate?

Yes, I uploaded an example site here: https://github.com/Jos512/hugo-shortcode-issue

That repository has example-post.md call the toc.html shortcode with {{<>}} and {{%%}} format. The content of that shortcode is:

{{ replace .Page.TableOfContents "TableOfContents" "toc" }}

How does the problem happen with the example site?

On Hugo 0.54, both {{<toc>}} and {{%toc%}} output:

<nav id="toc"> <ul> <li> <ul> <li><a href="#heading-1">Heading 1</a></li> <li><a href="#heading-2">Heading 2</a></li> </ul></li> </ul> </nav> 

This is correct; TableOfContents is replaced by toc.

On Hugo 0.55, both {{<toc>}} and {{%toc%}} output:

<nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#heading-1">Heading 1</a></li>
<li><a href="#heading-2">Heading 2</a></li>
</ul></li>
</ul>
</nav>

This is incorrect; the replace function doesn't replace "TableOfContents" with "toc" anymore.

What Hugo versions did you use for this test?

Hugo Static Site Generator v0.55.0/extended windows/amd64 BuildDate: unknown
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.12.2"
Hugo Static Site Generator v0.54.0/extended windows/amd64 BuildDate: unknown
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.11.5"
satotake added a commit to satotake/hugo that referenced this issue Apr 4, 2020
Add new Page Param ".TableOfContentsCollection" with goldmark
This enables users to customize table of contents as they like
You can be used it in shortcodes but have to use with `{{< >}}`
(as non-markdown shortcode)

Addresses gohugoio#7095, gohugoio#6811, gohugoio#6081, gohugoio#225
@bep

This comment has been minimized.

Copy link
Member

@bep bep commented Apr 7, 2020

Yes, that does not work and It will not be fixed. The TableOfContents is not available when we render the shortcode (think about it).

@bep bep closed this Apr 7, 2020
@bep

This comment has been minimized.

Copy link
Member

@bep bep commented Apr 7, 2020

@satotake and note that adding this as a "data container" would have the same problem. The shortcode is part of the ToC, so you get a "chicken and egg" problem. Please tell me how, but open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.