Skip to content

Commit 25814d6

Browse files
committed
fix(layouts): trim whitespace in render-codeblock placeholder/callout 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
1 parent 37ac898 commit 25814d6

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

layouts/_default/_markup/render-codeblock.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{{ $result := transform.HighlightCodeBlock . }}
22
{{- if or .Attributes.placeholders .Attributes.callout -}}
3-
{{ $code := highlight .Inner .Type }}
3+
{{- $code := highlight .Inner .Type -}}
44
{{- if .Attributes.placeholders -}}
5-
{{ $placeholderReplace := print "<div data-component='code-placeholder' class='code-placeholder-wrapper'><var title='Edit $0' class='code-placeholder' data-code-var='$0' data-code-var-value='$0' data-code-var-escaped=\"$0\">$0<span class='code-placeholder-edit-icon cf-icon Pencil'></span></var></div>" }}
6-
{{ $code = replaceRE .Attributes.placeholders $placeholderReplace $code }}
5+
{{- $placeholderReplace := print "<div data-component='code-placeholder' class='code-placeholder-wrapper'><var title='Edit $0' class='code-placeholder' data-code-var='$0' data-code-var-value='$0' data-code-var-escaped=\"$0\">$0<span class='code-placeholder-edit-icon cf-icon Pencil'></span></var></div>" -}}
6+
{{- $code = replaceRE .Attributes.placeholders $placeholderReplace $code -}}
77
{{- end -}}
88
{{- if .Attributes.callout -}}
9-
{{ $color := index .Attributes "callout-color" | default "green" }}
10-
{{ $calloutReplace := print "<span class='code-callout " $color "'>$0</span>" }}
11-
{{ $code = replaceRE .Attributes.callout $calloutReplace $code }}
9+
{{- $color := index .Attributes "callout-color" | default "green" -}}
10+
{{- $calloutReplace := print "<span class='code-callout " $color "'>$0</span>" -}}
11+
{{- $code = replaceRE .Attributes.callout $calloutReplace $code -}}
1212
{{- end -}}
13-
{{ $code | safeHTML }}
13+
{{- $code | safeHTML -}}
1414
{{- else -}}
1515
{{- $wrapped := string $result.Wrapped -}}
1616
{{- if in $wrapped "tc-dynamic-values" -}}

0 commit comments

Comments
 (0)