Skip to content

markup: Inconsistent heading attribute behaviour #14227

@n1xx1

Description

@n1xx1

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.152.2-6abdacad3f3fe944ea42177844469139e81feda6+extended windows/amd64 BuildDate=2025-10-24T15:31:49Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Description

I wanted to use slices as attributes (which goldmark supports) and found out they don't work as I expected. I did some tests on how goldmark attributes are handled in the headings and these are my finding:

render-heading.html

<h{{ .Level }}>{{ .Text }}</h{{ .Level }}>
<pre>{{ .Attributes | jsonify }}</pre>

_index.html

# Simple 1 {test=simple}

# Simple 1 
{test=simple}

# Slice 1 {test=[1, 2, 3]}

# Slice 1 
{test=[1, 2, 3]}

# Slice 2 {test=[1, 2, string]}

# Slice 2 
{test=[1, 2, string]}

# Nested 1 {test={a=1}}

# Nested 2 {test=[a, simple, "attribute", { with="nested values" }]}

# Nested 2
{test=[a, simple, "attribute", { with="nested values" }]}

Output:

<h1>Simple 1</h1>
<pre>{"id":"simple-1","test":"simple"}</pre>

<h1>Simple 1</h1>
<pre>{"id":"simple-1-1","test":"simple"}</pre>

<h1>Slice 1</h1>
<pre>{"id":"slice-1","test":[[0,0],[1,1],[2,2]]}</pre>

<h1>Slice 1</h1>
<pre>{"id":"slice-1-1","test":[[0,0],[1,1],[2,2]]}</pre>

<h1>Slice 2</h1>
<pre>{"id":"slice-2","test":[[0,0],[1,1]]}</pre>

<h1>Slice 2</h1>
<pre>{"id":"slice-2-1","test":[[0,0],[1,1]]}</pre>

<h1>Nested 1 {test={a=1}}</h1>
<pre>{"id":"nested-1-testa1"}</pre>

<h1>Nested 2 {test=[a, simple, &ldquo;attribute&rdquo;, { with=&ldquo;nested values&rdquo; }]}</h1>
<pre>{"id":"nested-2-testa-simple-attribute--withnested-values-"}</pre>

<h1>Nested 2</h1>
<pre>{"id":"nested-2","test":null}</pre>

Also the next example fails with this error: Error: error building site: render: failed to render pages: render of ".../repro-hugo-goldmark-attributes/content/_index.md" failed: "...\repro-hugo-goldmark-attributes\layouts\baseof.html:13:13": execute of template failed: template: list.html:13:13: executing "main" at <.Content>: error calling Content: not implemented: parser.Attributes

# Nested 1 
{test={a=1}}

Repro

https://github.com/n1xx1/repro-hugo-goldmark-attributes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions