Skip to content

Bug Report: Runtime panic (index out of range) in TOC generation with nested extension nodes #14677

@QingGo

Description

@QingGo

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

$ hugo version
hugo v0.159.1+extended+withdeploy darwin/amd64 BuildDate=2026-03-26T09:54:15Z VendorInfo=Homebrew

Does this issue reproduce with the latest release?

Yes

Description of the bug

Hugo panics with runtime error: index out of range during site builds when calling .Summary or generating a Table of Contents (TOC) for pages that contain specific Markdown extension nodes (like LaTeX/Passthrough) nested inside standard nodes (like Emphasis) within a heading.

The panic occurs in markup/goldmark/toc.go. Hugo's TOC renderer is a simplified Goldmark renderer that does not have all extensions registered. When it encounters an unknown node kind ID (e.g., from the Passthrough extension) while recursively rendering a heading's children, Goldmark's internal renderer attempts to access an out-of-bounds index in its renderer function slice.

What did you expect to see?

The site should build successfully. The TOC renderer should gracefully handle or ignore node types it doesn't recognize.

What did you see instead?

The build crashes with a panic:
panic: runtime error: index out of range [41] with length 41 (The index may vary depending on the extension's Kind ID).

Page/Config that reproduces the issue

hugo.toml

[markup.goldmark.extensions.passthrough]
  enable = true
[markup.goldmark.extensions.passthrough.delimiters]
  inline = [['$', '$']]

content/repro.md

---
title: "Repro"
---
#### **$a$**

layouts/_default/single.html

{{ .Summary }}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions