Skip to content

fix(layouts): trim whitespace in render-codeblock placeholder/callout branch#7084

Merged
jstirnaman merged 1 commit intomasterfrom
claude/fix-render-codeblock-whitespace-7079
Apr 9, 2026
Merged

fix(layouts): trim whitespace in render-codeblock placeholder/callout branch#7084
jstirnaman merged 1 commit intomasterfrom
claude/fix-render-codeblock-whitespace-7079

Conversation

@jstirnaman
Copy link
Copy Markdown
Contributor

Summary

Fixes the root cause of the site-wide broken-code-block regression reported in #7079. The merged PR #7083 collapsed two wrapper shortcode templates as a band-aid that worked around the visible symptom on sample-data pages, but the same bug was still affecting ~18 other admin/install pages with placeholder code blocks (e.g. /influxdb3/enterprise/admin/backup-restore/, /influxdb3/clustered/admin/users/add/, /influxdb3/enterprise/admin/upgrade/). This PR fixes the underlying cause in layouts/_default/_markup/render-codeblock.html.

Root cause

Commit d80eb2f from #7069 (Apr 8) refactored render-codeblock.html to support the new callout fence attribute alongside placeholders. The refactor introduced a new conditional branch:

{{- if or .Attributes.placeholders .Attributes.callout -}}
  {{ $code := highlight .Inner .Type }}
  {{- if .Attributes.placeholders -}}
    {{ $placeholderReplace := print "<div data-component='code-placeholder'..." }}
    {{ $code = replaceRE .Attributes.placeholders $placeholderReplace $code }}
  {{- end -}}
  ...
  {{ $code | safeHTML }}

The outer {{- if -}} trims its own surrounding whitespace, but the inner action tags use bare {{ ... }} instead of {{- ... -}}. Each bare assignment leaks its leading indent (2 or 4 spaces) and trailing newline into the rendered output. For a placeholder code block the final render-hook output looks like:

  
    
    
  <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash"...

Goldmark sees a run of indented whitespace-only lines followed by an indented HTML block, interprets the leading portion as an indented code block, wraps it in <pre><code>, and HTML-escapes every <&lt;. Users see a wall of escaped <span class="line"> fragments instead of a code block.

The else branch (non-placeholder/non-callout code blocks) already uses {{- ... -}} on every action, which is why ordinary code blocks were unaffected. The regression only hit pages that use either the placeholders or callout fence attribute — i.e. almost every admin CLI / install / backup / sample-data page.

Fix

Apply {{- ... -}} whitespace trimming to every action inside the if or .Attributes.placeholders .Attributes.callout branch, matching the pattern the else branch already uses. No content files change, no shortcode templates change.

-  {{ $code := highlight .Inner .Type }}
+  {{- $code := highlight .Inner .Type -}}
-    {{ $placeholderReplace := print "..." }}
-    {{ $code = replaceRE .Attributes.placeholders $placeholderReplace $code }}
+    {{- $placeholderReplace := print "..." -}}
+    {{- $code = replaceRE .Attributes.placeholders $placeholderReplace $code -}}
...
-  {{ $code | safeHTML }}
+  {{- $code | safeHTML -}}

Why not keep the collapse band-aid from #7083

The collapses in layouts/shortcodes/influxdb/custom-timestamps.html and layouts/shortcodes/code-tab-content.html fixed the sample-data pages only. They didn't help pages that wrap placeholder code blocks in other shortcodes (tab-content, expand, plain bullet lists, etc.), which is why backup-restore, users/add, upgrade, and ~15 others were still broken. Fixing render-codeblock.html itself eliminates the class of bug everywhere in one place, so any wrapper shortcode works correctly regardless of whether its template has indented .Inner.

Verification

Built locally with Hugo 0.149.0 extended against origin/master plus this commit.

Site-wide count of pages containing the escaped-highlight pattern (&lt;div class=&quot;highlight):

State Count
master (before #7083) 23 pages
master (with #7083 band-aid) 18 pages
this branch 0 pages

Specific pages spot-checked:

  • /influxdb3/enterprise/admin/backup-restore/
  • /influxdb3/enterprise/admin/upgrade/
  • /influxdb3/enterprise/admin/mcp-server/
  • /influxdb3/enterprise/admin/backup-restore/
  • /influxdb3/enterprise/admin/upgrade-from-core/
  • /influxdb3/enterprise/reference/cli/influxdb3/write/
  • /influxdb3/enterprise/write-data/best-practices/optimize-writes/
  • /influxdb3/clustered/admin/users/add/
  • /influxdb3/clustered/install/secure-cluster/auth/
  • /influxdb3/clustered/write-data/best-practices/optimize-writes/
  • /influxdb3/explorer/install/
  • All 5 sample-data pages (core, enterprise, cloud-dedicated, clustered, cloud-serverless) ✅
  • /influxdb3/core/get-started/write/ and /query/ — no regressions ✅

Follow-ups (not in this PR)

Test plan

  • Local Hugo 0.149 build succeeds
  • Site-wide escaped-highlight count drops to 0
  • Sample-data pages render correctly
  • Backup-restore, upgrade, users/add pages render correctly
  • PR preview visual check on /influxdb3/enterprise/admin/backup-restore/
  • CI checks pass

Closes #7079

… branch

Commit d80eb2f (#7069) refactored `layouts/_default/_markup/render-codeblock.html`
to support the new `callout` fence attribute alongside the existing
`placeholders` attribute. The refactor introduced a new conditional
branch that handles placeholder/callout code blocks, but several of its
interior action tags use bare `{{ ... }}` delimiters instead of the
whitespace-trimming `{{- ... -}}` form used in the `else` branch:

    {{- if or .Attributes.placeholders .Attributes.callout -}}
      {{ $code := highlight .Inner .Type }}
      ...
      {{ $code | safeHTML }}

Each non-trimmed action leaks two leading spaces and a trailing newline
into the render-hook output. For a placeholder code block the final
render-hook output then looks like:

    [2 spaces][newline]
    [4 spaces][newline]
    [4 spaces][newline]
    [2 spaces]<div class="highlight">...</div>[newline]

Goldmark sees this as an indented code block preceded by blank lines,
wraps the leading highlighted HTML in `<pre><code>`, and HTML-escapes
every `<` and `>`. The visible symptom is a wall of escaped
`<span class="line">...` fragments on every page with a placeholder or
callout code block, including every InfluxDB 3 sample-data page, the
enterprise backup-restore page, the clustered users/add page, and
about 18 other admin pages. The regression landed on Apr 8 with #7069
and was reported as #7079.

Fix: apply `{{- ... -}}` whitespace trimming to every action inside the
placeholder/callout branch, matching the pattern the `else` branch
already uses. No content files change. Verified with a local Hugo 0.149
build — every previously affected page now renders with zero escaped
highlight blocks, and the site-wide count of pages containing
`&lt;div class=&quot;highlight` drops from 23 to 0.

Closes #7079
@jstirnaman jstirnaman requested a review from a team as a code owner April 9, 2026 21:34
@jstirnaman jstirnaman requested review from sanderson and removed request for a team April 9, 2026 21:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

PR Preview Action v1.4.8
🚀 Deployed preview to https://influxdata.github.io/docs-v2/pr-preview/pr-7084/
on branch gh-pages at 2026-04-09 21:37 UTC

@jstirnaman jstirnaman merged commit 1c38888 into master Apr 9, 2026
14 checks passed
github-actions bot added a commit that referenced this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken HTML formatting in sample data pages

2 participants