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

.RenderShortcodes generates artifact when used nested in HTML #12854

Closed
McShelby opened this issue Sep 16, 2024 · 10 comments · Fixed by #12996
Closed

.RenderShortcodes generates artifact when used nested in HTML #12854

McShelby opened this issue Sep 16, 2024 · 10 comments · Fixed by #12996

Comments

@McShelby
Copy link

McShelby commented Sep 16, 2024

Configured renderer.unsafe=true and then using .RenderShortcodes in a shortcode used with % generates artifacts in the form of {{__hugo_ctx pid=3}}.

Is this intended?

This can be seen in the sample repo in http:/localhost:1313/posts

https://github.com/McShelby/hugo-testing/tree/hugo-issue-12854

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

$ hugo version
hugo v0.134.2-1c74abd26070b0c12849550c974a9f3f1e7afb06 windows/amd64 BuildDate=2024-09-10T10:46:33Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes. The used version was the latest.

@bep
Copy link
Member

bep commented Sep 16, 2024

Is this intended?

No, but I'm assuming you're doing something ... unusual that we didn't think of when we implemented this. Because it doesn't always happen.

@bep bep removed the NeedsTriage label Sep 16, 2024
@bep bep added this to the Unscheduled milestone Sep 16, 2024
@bep bep added the S0 label Sep 16, 2024
@McShelby
Copy link
Author

Hm. I stripped the sample down to the bones. In my view, nothing special here.

@bep
Copy link
Member

bep commented Sep 16, 2024

This usage is unusual:

{{- range .Page.Pages }}
<h3>{{ .Title | safeHTML }}</h3>
<div>{{ .RenderShortcodes | safeHTML }}</div>
{{- end }}

I suggest you read the documentation and/or start a thread in the forum about the intention/use cases of .RenderShortcodes. It's a method with very limited but useful use: Including markdown in markdown, so to speak.

@bep bep changed the title .RenderShortcodes generates artifacts .RenderShortcodes generates artifact when used nested in HTML Sep 16, 2024
@McShelby
Copy link
Author

For others who may come around: The artifacts seem to be avoided if the shortcode is changed by adding a blank line in front of .RenderShortcodes.

{{- range .Page.Pages }}
<h3>{{ .Title | safeHTML }}</h3>
<div>

{{ .RenderShortcodes | safeHTML }}
</div>
{{- end }}

@bep
Copy link
Member

bep commented Sep 17, 2024

For others who may come around:

Please read and understand the documentation at https://gohugo.io/methods/page/rendershortcodes/ and consider if you really need to use this method. It is very useful, but it a special purpose method.

If you wrap your .RenderShortcodes in a div and pipe it to safeHTML, the answer is no.

@McShelby
Copy link
Author

Thanks bep for the fix.

Just for clarification, does this fix change your statement from above?

If you wrap your .RenderShortcodes in a div and pipe it to safeHTML, the answer is no.

@bep
Copy link
Member

bep commented Oct 30, 2024

Just for clarification, does this fix change your statement from above?

No.

The fix is to catch an error situation. I will print a warning (that can be turned off) about it.

The only use case I can think of for .RenderShortcodes is to include markdown blocks. Anything else just doesn't work.

bep added a commit to bep/hugo that referenced this issue Oct 31, 2024
bep added a commit to bep/hugo that referenced this issue Oct 31, 2024
This issue fixes two cases where `{{__hugo_ctx` artifacts were left in the rendered output:

1. Inclusion when `.RenderShortcodes` is wrapped in HTML.
2. Inclusion of Markdown file without a trailing newline in some cases.

Closes gohugoio#12854
@bep
Copy link
Member

bep commented Oct 31, 2024

Just for clarification, does this fix change your statement from above?

That said, the PR fixes 2 issues with similar symptoms (see test cases); one of them is perfectly valid use ...

@jmooring
Copy link
Member

jmooring commented Oct 31, 2024

@McShelby

adding a blank line

This is required per the CommonMark specification for HTML blocks. Specifically, read about the end condition for the sixth "type" of HTML block.

bep added a commit to bep/hugo that referenced this issue Nov 1, 2024
This issue fixes two cases where `{{__hugo_ctx` artifacts were left in the rendered output:

1. Inclusion when `.RenderShortcodes` is wrapped in HTML.
2. Inclusion of Markdown file without a trailing newline in some cases.

Closes gohugoio#12854
bep added a commit to bep/hugo that referenced this issue Nov 2, 2024
This issue fixes two cases where `{{__hugo_ctx` artifacts were left in the rendered output:

1. Inclusion when `.RenderShortcodes` is wrapped in HTML.
2. Inclusion of Markdown file without a trailing newline in some cases.

Closes gohugoio#12854
Updates gohugoio#12998
bep added a commit to bep/hugo that referenced this issue Nov 3, 2024
This issue fixes two cases where `{{__hugo_ctx` artifacts were left in the rendered output:

1. Inclusion when `.RenderShortcodes` is wrapped in HTML.
2. Inclusion of Markdown file without a trailing newline in some cases.

Closes gohugoio#12854
Updates gohugoio#12998
bep added a commit to bep/hugo that referenced this issue Nov 3, 2024
This issue fixes two cases where `{{__hugo_ctx` artifacts were left in the rendered output:

1. Inclusion when `.RenderShortcodes` is wrapped in HTML.
2. Inclusion of Markdown file without a trailing newline in some cases.

Closes gohugoio#12854
Updates gohugoio#12998
@bep bep closed this as completed in #12996 Nov 3, 2024
@bep bep closed this as completed in 1f23b49 Nov 3, 2024
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants