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

Error when JSON fenced code block contains shortcode call #12567

Open
jmooring opened this issue Jun 4, 2024 · 4 comments
Open

Error when JSON fenced code block contains shortcode call #12567

jmooring opened this issue Jun 4, 2024 · 4 comments
Labels
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Jun 4, 2024

Reference: https://discourse.gohugo.io/t/panic-with-json-and-workaround-but-better-to-fix-it/50137/9

markdown

```json
{{< sc >}}
```

error

Error: error building site: render: failed to render pages: render of "home" failed: "/home/jmooring/code/hugo-testing/layouts/_default/home.html:11:5": execute of template failed: template: _default/home.html:11:5: executing "main" at <.Content>: error calling Content: unknown shortcode token "HAHAHUGOSHORTCODE<span style="color:#ae81ff">1<span style="color:#960050;background-color:#1e0010">s<span style="color:#ae81ff">0<span style="color:#960050;background-color:#1e0010">HBHB" (number of tokens: 1)

The problem seems to be limited to the JSON hiighlighting language. I tested about 20 other languages, including some likely suspects, but was unable to reproduce the problem.

This isn’t a problem if you call the shortcode using the {{% %}} notation. The shortcode template itself is irrelevant.

It looks like we started throwing this error in v0.111.0 and later, but as far as I can tell this combination has never worked.

Low priority.

@FuadEfendi
Copy link

Perhaps we can just have separate syntax validator tool, instead of whole server routine

@jmooring
Copy link
Member Author

jmooring commented Jun 6, 2024

syntax validator tool

There's nothing invalid about the unclosed fenced code blocks that you described in the original forum topic. It may not be what you intend, but the markdown itself is valid.

Perhaps you can find a linter that warns you about unclosed fenced code blocks, but the best known linter (markdownlint) does not have this capability. See:

DavidAnson/markdownlint#331

This issue is not related to unclosed fenced code blocks in any way.

@FuadEfendi
Copy link

FuadEfendi commented Jun 6, 2024

Ok, as I understand this syntax is correct:

```json
{{< sc >}}
```

The issue is that Hugo just throws panic

Maybe I can just write Java application which can find all such specific patterns and report... with IDE, I am more or less successful and fast using search for "json" in files; but initially I was doing "binary search" to find why it fails, removing half of files then starting server until I find suspect.

I didn't see such issue with other patterns such as "mermaid"; only with "json".

@jmooring
Copy link
Member Author

jmooring commented Jun 7, 2024

I didn't see such issue with other patterns such as "mermaid"; only with "json".

That's why the issue title is:

Error when JSON fenced code block contains shortcode call

It is specific to fenced code blocks where the language portion of the info string is "JSON".

@bep bep added this to the v0.130.0 milestone Jul 22, 2024
@bep bep removed the NeedsTriage label Jul 22, 2024
@bep bep modified the milestones: v0.130.0, v0.131.0 Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants