{"id":"658acd794984031f","repo":"gohugoio/hugo","slug":"illegal-state-in-content-shortcode-token-missing","errorCode":null,"errorMessage":"illegal state in content; shortcode token missing end delim","messagePattern":"illegal state in content; shortcode token missing end delim","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"hugolib/shortcode.go","lineNumber":744,"sourceCode":"\tctx context.Context,\n\tsource []byte,\n\ttokenHandler func(ctx context.Context, token string) ([]byte, error),\n) ([]byte, error) {\n\tstart := 0\n\n\tpre := []byte(shortcodePlaceholderPrefix)\n\tpost := []byte(\"HBHB\")\n\tpStart := []byte(\"<p>\")\n\tpEnd := []byte(\"</p>\")\n\n\tk := bytes.Index(source[start:], pre)\n\n\tfor k != -1 {\n\t\tj := start + k\n\t\tpostIdx := bytes.Index(source[j:], post)\n\t\tif postIdx < 0 {\n\t\t\t// this should never happen, but let the caller decide to panic or not\n\t\t\treturn nil, errors.New(\"illegal state in content; shortcode token missing end delim\")\n\t\t}\n\n\t\tend := j + postIdx + 4\n\t\tkey := string(source[j:end])\n\t\tnewVal, err := tokenHandler(ctx, key)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\t// Issue #1148: Check for wrapping p-tags <p>\n\t\tif j >= 3 && bytes.Equal(source[j-3:j], pStart) {\n\t\t\tif (k+4) < len(source) && bytes.Equal(source[end:end+4], pEnd) {\n\t\t\t\tj -= 3\n\t\t\t\tend += 4\n\t\t\t}\n\t\t}\n\n\t\t// This and other cool slice tricks: https://github.com/golang/go/wiki/SliceTricks","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/shortcode.go#L726-L762","documentation":"After markdown rendering, Hugo replaces placeholder tokens (prefix ... 'HBHB' end marker) in the rendered output with the actual shortcode results. This error means a token's start prefix was found but its 'HBHB' end delimiter was not — the placeholder was corrupted between insertion and expansion. It is an internal invariant violation ('should never happen'), not a user syntax error per se.","triggerScenarios":"expandShortcodeTokens finding the shortcode placeholder prefix in rendered content without a following 'HBHB' marker. This occurs when the markdown renderer or a filter mutates, splits, or truncates the placeholder string — e.g. a render hook, custom Goldmark extension, or a template transformation altering the token text.","commonSituations":"Custom markdown render hooks or output filters that transform text containing the placeholder; shortcodes placed in contexts where the renderer escapes or breaks the token (e.g. inside code processing or transformed attributes); very rarely a Hugo bug after version upgrades — historically reported around unusual shortcode placement.","solutions":["Identify which page fails and simplify: temporarily remove shortcodes one at a time to find the placement (e.g. inside a code block, link title, or attribute) whose rendering mangles the token.","Check custom render hooks/markup filters that rewrite rendered text and exclude Hugo's shortcode placeholder tokens from transformation.","Update Hugo to the latest release, and if it still reproduces with a minimal case, report it as a bug — this state indicates an internal invariant break."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Detect unterminated shortcode delimiters in content\n// grep -nE '\\{\\{[<%]([^}]|\\}[^}])*$' content/**/*.md","typeGuard":null,"tryCatchPattern":"if err := h.Build(cfg); err != nil {\n    // 'missing end delim' means a {{< or {{% was never closed with >}} / %}}\n    // find the last shortcode open in the named file\n    return err\n}","preventionTips":["Every {{< must be terminated with >}} and every {{% with %}} on the same logical token","Watch for truncated files from bad merges or generators cutting content mid-shortcode","Don't mix delimiter styles in one call ({{< ... %}} is malformed)","Add an editor snippet that inserts both delimiters at once so they can't be left unbalanced"],"tags":["hugo","shortcode","internal","rendering","invariant"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}