gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75k stars 7.47k forks source link

Error when JSON fenced code block contains shortcode call #12567

Open jmooring opened 3 months ago

jmooring commented 3 months ago

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><span style=\"color:#ae81ff\">1</span><span style=\"color:#960050;background-color:#1e0010\">s</span><span style=\"color:#ae81ff\">0</span><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 commented 3 months ago

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

jmooring commented 3 months ago

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:

https://github.com/DavidAnson/markdownlint/issues/331

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

FuadEfendi commented 3 months ago

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 commented 3 months ago

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