{"id":"b6fd223fc10ad206","repo":"gohugoio/hugo","slug":"unknown-shortcode-token-q-number-of-tokens-d","errorCode":null,"errorMessage":"unknown shortcode token %q (number of tokens: %d)","messagePattern":"unknown shortcode token %q \\(number of tokens: (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"hugolib/page__content.go","lineNumber":562,"sourceCode":"\t\t\t}\n\n\t\t\t// There are one or more replacement tokens to be replaced.\n\t\t\tvar hasShortcodeVariants bool\n\t\t\ttokenHandler := func(ctx context.Context, token string) ([]byte, error) {\n\t\t\t\tif token == tocShortcodePlaceholder {\n\t\t\t\t\treturn []byte(ct.tableOfContentsHTML), nil\n\t\t\t\t}\n\t\t\t\trenderer, found := ct.contentPlaceholders[token]\n\t\t\t\tif found {\n\t\t\t\t\trepl, more, err := renderer.renderShortcode(ctx)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\thasShortcodeVariants = hasShortcodeVariants || more\n\t\t\t\t\treturn repl, nil\n\t\t\t\t}\n\t\t\t\t// This should never happen.\n\t\t\t\tpanic(fmt.Errorf(\"unknown shortcode token %q (number of tokens: %d)\", token, len(ct.contentPlaceholders)))\n\t\t\t}\n\n\t\t\tb, err = expandShortcodeTokens(ctx, b, tokenHandler)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif hasShortcodeVariants {\n\t\t\t\tcp.po.p.incrPageOutputTemplateVariation()\n\t\t\t}\n\n\t\t\tvar result contentSummary\n\t\t\tif c.pi.hasSummaryDivider {\n\t\t\t\ts := string(b)\n\t\t\t\tsummarized := page.ExtractSummaryFromHTMLWithDivider(cp.po.p.m.pageConfigSource.ContentMediaType, s, internalSummaryDividerBase)\n\t\t\t\tresult.summary = page.Summary{\n\t\t\t\t\tText:      template.HTML(summarized.Summary()),\n\t\t\t\t\tType:      page.SummaryTypeManual,\n\t\t\t\t\tTruncated: summarized.Truncated(),","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/page__content.go#L544-L580","documentation":"A panic raised by the token handler in page__content.go's content-rendering path when, after markdown processing, Hugo finds a HUGOSHORTCODE-style placeholder token in the output that has no matching entry in ct.contentPlaceholders. The code comments this as \"should never happen\" — it indicates internal state corruption: a placeholder survived into rendered content without a registered renderer.","triggerScenarios":"expandShortcodeTokens encounters a placeholder string in Goldmark output that isn't in the placeholder map. In practice: content or a markdown render hook that synthesizes/duplicates text containing a raw `HAHAHUGOSHORTCODE` placeholder, or a Hugo bug where placeholder bookkeeping diverges between parse and render (e.g. cached content reused across edits in `hugo server`).","commonSituations":"Render hooks or shortcodes that echo page content verbatim (duplicating placeholder tokens); pathological content literally containing the internal placeholder marker; stale-cache states in long-running `hugo server` sessions after rapid edits; rarely, genuine regressions in a new Hugo release.","solutions":["Restart `hugo server` (or run `hugo --gc` and clear resources/_gen and the cacheDir) to rule out stale cached content state.","Search content and layouts for anything emitting the literal internal placeholder pattern (e.g. `grep -r HAHAHUGOSHORTCODE content layouts`) and remove it.","Check whether a render hook or shortcode copies raw page source (.RawContent) into output — that duplicates placeholders; use .Content or rework the hook.","If reproducible on a clean build, minimize the site and report it as a bug at github.com/gohugoio/hugo — this path is an internal invariant violation (it panics)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// don't manipulate rendered content in ways that split/drop shortcode placeholder tokens\n// e.g. avoid truncating .Content or regex-replacing over raw placeholder markers before rendering completes","typeGuard":null,"tryCatchPattern":"if _, err := p.Content(ctx); err != nil && strings.Contains(err.Error(), \"unknown shortcode token\") {\n    // internal token mismatch — usually a content-mangling markup hook or truncation\n    return err\n}","preventionTips":["Do not post-process markdown output with hooks that strip or rewrite unknown HTML comments (placeholders live there)","Use .Summary/.Truncated APIs instead of hand-slicing rendered content","Report reproducers upstream — this is an internal invariant violation, not normal user error"],"tags":["hugo","shortcode","panic","internal-state","rendering"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}