Skip to content

Error "unknown shortcode token" when calling shortcode within fenced code block #10819

@jmooring

Description

@jmooring

N.B. I'm not sure if this is a bug, or if we've fixed a bug.

Reproducible with v0.111.0 and later.

If a shortcode is called using the {{< >}} notation within a fenced code block, Chroma lexes the placeholder, triggering an error such as:

unknown shortcode token "HAHAHUGOSHORTCODE<span style="color:#f92672">-<span style="color:#a6e22e">s0<span style="color:#f92672">-<span style="color:#a6e22e">HBHB"

But this does not happen with all lexers, and may depend on where the shortcode is placed within the codeblock (not sure).

For example, this works:

```bash
{{< sc >}}
```

But this throws an error:

```go
{{< sc >}}
```

And both of these work:

```bash
{{% sc %}}
```

```go
{{% sc %}}
```

What the shortcode does is irrelevant (e.g., it can be empty).

Reference: https://discourse.gohugo.io/t/43387 (Kubernetes site)

Simple example:

git clone --single-branch -b hugo-forum-topic-43387 https://github.com/jmooring/hugo-testing hugo-forum-topic-43387
cd hugo-forum-topic-43387
hugo server

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions