What is meant by "closed or self-closed"

The docs say: “Any shortcode that refers to .Inner must be closed or self-closed.” Since 0.111, this is enforced the hard way: Hugo fails on our long-standing site with error messages like

failed to extract shortcode: shortcode "..." must be closed or self-closed

Seems it is time for us to understand what you mean by “closed or self-closed”. Are these terms defined somewhere? Are there examples? How can we debug this issue?

As a minimal example, this file anchor.html is broken:

<anchor id="{{.Get 0}}">{{.Inner}}</anchor>

One more question: How was an illegal {{.Inner}} handled prior to 0.111? Was it ignored, or executed at our own risk?

Closed:

{{< highlight html >}}
...
{{< /highlight >}}

Self-closed:

{{< innershortcode />}}

And a “unclosed” shortcode:

{{< date >}}

How does that apply to the above “anchor” example?

Perhaps I also need definitions of “shortcode” and “that refers to .Inner”.

Works well, but I don’t know what is your project…

The shortcode file layouts/shortcodes/anchor.html is your code:

<anchor id="{{.Get 0}}">{{.Inner}}</anchor>

In my markdown page:

text

{{< anchor myID >}}
    MyTextInside
{{< /anchor >}}

text

The output:

<p>text</p>

<anchor id="myID">
    MyTextInside
</anchor>

<p>text</p>

Summary:

  1. Content in the short code (between the opening markup and the closing markup)
    .Inner
  2. Content in the call of the shortcode is a parameter
    → the first one is .Get 0

Thanks for your explanations. Purpose of .Inner starts getting clearer to me.

But … you say “Works well”, whereas hugo 0.111 says “must be closed or self-closed” - ???

Your shortcode call must be closed. It is.

Excellent.

That leaves me with just one remaining question: How to debug? How to find the incorrect call?

Isn’t that printed in the console?

Calling code _index.md reduced to

+++
title = "Documentation"
weight = 50
+++

{{% anchor "test"  %}}

Still fails, now with

Error: Error building site: "xxx/content/_index.md:6:1": failed to extract shortcode: unclosed shortcode "anchor"

I am clueless, desperate, and very disappointed.

The entire site compiled without a single warning under 0.110.

It points to a file and a line and column number. Why not open that file and fix the issue?

We fixed a bug. Earlier this error situation was just ignored and the content was truncated. Getting an error message that’s easy to fix is a much better situation.

1 Like

It points to a file and a line and column number. Why not open that file and fix the issue?

I posted the entire file just above:

+++
title = "Documentation"
weight = 50
+++

{{% anchor "test"  %}}

What is wrong here? What is unclosed or not self-closed?

We fixed a bug. Earlier this error situation was just ignored

Per Hyrum’s law, users write code that is supported by your compiler, not code that complies with your specification. The more so if the specification is a bit thin.

1 Like

Instead of

{{% anchor "test" %}}

write

{{% anchor "test" /%}}
1 Like

In the end, I just removed the {{.Inner}}. Output seems to be ok.

Let me hope that the {{.Inner}} was pointless from the onset, and was ignored by previous versions of Hugo, so that nothing has been broken now.

Cordial invitation to the maintainers of Hugo to improve the error message, to expand the explanation in the docs, and to rethink their policy on breaking backwards compatibility.

To stay with your citation: If you upgrade your compiler, often you have to make code changes so it compiles with the newer version.

If you don’t want to go that road, you can still use the old compiler version.

Same here with Hugo.

breaking backwards compatibility

Your code was wrong in the first place. This isn’t the same as being backwards compatible.

Again Hyrum’s law. The user code, which now turns out to be wrong, was encouraged by a compiler, which now is said to have had a bug.

So you are right about terminology. I do not just want backwards compatibility. I want bug compatibility. And if that cannot be achieved with reasonable effort, then at least I want clear and precise error messages.

You WANT a lot of things for an open source software …

2 Likes

Clear and precise error message is what you might get. Hugo is in active development state, so breaking changes are bound to happen, but backwards compatibility is maintained for features that affect a lot of (old) users.