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

Markdown code block within fully rendered shortcode should not be parsed for HTML syntax errors #9821

Open
landure opened this issue Apr 25, 2022 · 6 comments

Comments

@landure
Copy link

landure commented Apr 25, 2022

Using

hugo v0.97.3+extended linux/amd64 BuildDate=unknown

I created this shortcode in the file shortcodes/docker/external_networks_creation.md:

external_networks_creation.md

When the shortcode is called using:

{{% docker/external_networks_creation networks="traefik_network,prometheus_network" %}}

The following ERROR is triggered:

ERROR 2022/04/25 14:55:07 "content/posts/some-post.md:92:1": failed to render shortcode "docker/external_networks_creation": failed to process shortcode: execute of template failed: html/template:shortcodes/docker/external_networks_creation.md: ends in a non-text context: {stateAfterName delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>}
Total in 70 ms

Replacing EOF by quotes (") fixes the issue.

@jmooring
Copy link
Member

jmooring commented Apr 25, 2022

Confirmed. This has been an issue since at least v0.54.0 (I didn't test anything earlier). Simplied example...

layouts/shortcodes/foo.html

```
<x
```

markdown

{{% foo %}}

<x is detected as the beginning of an HTML element, without a closing >. This also occurs if the code block is created via indentation (>= 4 spaces) instead of with fences.

@jmooring jmooring changed the title "EOF" in shortcode trigger parse error. Markdown code block within fully rendered shortcode should not be parsed for HTML syntax errors Apr 25, 2022
@landure
Copy link
Author

landure commented Apr 26, 2022

This error occurs when <is not followed by space. It occurs with or without code block:

layouts/shortcodes/foo.md

<o

@landure
Copy link
Author

landure commented Apr 26, 2022

A temporary fix is using safeHTML function:

layouts/shortcodes/foo.md

{{ safeHTML "<" }}o

@bep bep added this to the v0.99.0 milestone Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep added Upstream and removed NeedsTriage labels May 27, 2022
@bep
Copy link
Member

bep commented May 27, 2022

This smells like an upstream issue that someone needs to raise at https://github.com/golang/go/issues/

layouts/shortcodes/foo.md

{{ safeHTML "<" }}o

You can also create a new output format for md and set isPlainText=true, see https://gohugo.io/templates/output-formats/#configure-output-formats

This will use Go's text (not HTML) parser.

EDIT: Thinking about it, I'm not totally sure that the above would work, but I'll think about it.

bep added a commit to bep/hugo that referenced this issue May 27, 2022
@bep
Copy link
Member

bep commented May 27, 2022

I have tested the above, and that works fine.

I added a PR in #9940 which I need to think a little about whether is a great idea. But in any case, you can define this output format in your site config in the existing Hugo versions and it should work.

bep added a commit to bep/hugo that referenced this issue May 27, 2022
The motivation behind this is not to make it easier to publish Markdown files, as that sounds unusual.

This is mainly meant for shortcodes that produces Markdown to be inlined.

You would do this by creating shortcodes with `*.md` suffix (e.g. `layouts/shortcodes/myshortcode.md`).

This output format is defined as plain text, and will use Go's much more lenient text template parser.

Updates gohugoio#9821
@landure
Copy link
Author

landure commented May 28, 2022

Would it be possible to set {%%} shortcode call to use Go text parser ? As far as I understand {%%} called short codes results are then processed as markdown, not as html like the {<>}. It should not need the addition of a new output format ?

bep added a commit to bep/hugo that referenced this issue May 29, 2022
The motivation behind this is not to make it easier to publish Markdown files, as that sounds unusual.

This is mainly meant for shortcodes that produces Markdown to be inlined.

You would do this by creating shortcodes with `*.md` suffix (e.g. `layouts/shortcodes/myshortcode.md`).

This output format is defined as plain text, and will use Go's much more lenient text template parser.

Updates gohugoio#9821
bep added a commit to bep/hugo that referenced this issue May 29, 2022
The motivation behind this is not to make it easier to publish Markdown files, as that sounds unusual.

This is mainly meant for shortcodes that produces Markdown to be inlined.

You would do this by creating shortcodes with `*.md` suffix (e.g. `layouts/shortcodes/myshortcode.md`).

This output format is defined as plain text, and will use Go's much more lenient text template parser.

Updates gohugoio#9821
bep added a commit to bep/hugo that referenced this issue May 30, 2022
The motivation behind this is not to make it easier to publish Markdown files, as that sounds unusual.

This is mainly meant for shortcodes that produces Markdown to be inlined.

You would do this by creating shortcodes with `*.md` suffix (e.g. `layouts/shortcodes/myshortcode.md`).

This output format is defined as plain text, and will use Go's much more lenient text template parser.

Updates gohugoio#9821
bep added a commit to bep/hugo that referenced this issue May 30, 2022
The motivation behind this is not to make it easier to publish Markdown files, as that sounds unusual.

This is mainly meant for shortcodes that produces Markdown to be inlined.

You would do this by creating shortcodes with `*.md` suffix (e.g. `layouts/shortcodes/myshortcode.md`).

This output format is defined as plain text, and will use Go's much more lenient text template parser.

Updates gohugoio#9821
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep modified the milestones: v0.101.0, v0.102.0 Jun 16, 2022
@bep bep modified the milestones: v0.102.0, v0.103.0 Aug 28, 2022
@bep bep modified the milestones: v0.103.0, v0.104.0 Sep 15, 2022
@bep bep modified the milestones: v0.109.0, v0.110.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants