Skip to content

fix: blank lines in description produce whitespace-only lines in YAML frontmatter - #598

Open
javabrett wants to merge 1 commit into
hashicorp:mainfrom
javabrett:fix/prefixlines-blank-line-whitespace
Open

javabrett wants to merge 1 commit into
hashicorp:mainfrom
javabrett:fix/prefixlines-blank-line-whitespace

Conversation

@javabrett

Copy link
Copy Markdown

Summary

When a provider resource's Description (or MarkdownDescription) contains blank lines — for example, surrounding a code fence — the generated YAML frontmatter ends up with whitespace-only lines ( , two spaces) instead of genuinely blank lines.

Root cause

PrefixLines in internal/tmplfuncs/tmplfuncs.go was implemented as:

return prefix + strings.Join(strings.Split(text, "\n"), "\n"+prefix)

strings.Split produces an empty string "" for each blank line. strings.Join then inserts "\n" + prefix before that empty string, yielding a line that is just the prefix (e.g. " ") with no content.

The prefixlines " " template filter is used in the YAML frontmatter block scalar in all four default templates (resource, data source, function, action):

description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines "  " }}

So any blank line in a provider description becomes a whitespace-only line in the generated docs/ output.

Fix

Skip adding the prefix when the line is empty:

lines := strings.Split(text, "\n")
for i, line := range lines {
    if line != "" {
        lines[i] = prefix + line
    }
}
return strings.Join(lines, "\n")

Tests

Added internal/tmplfuncs/tmplfuncs_test.go with unit tests for PrefixLines, including the blank-line regression case. The failing test case with the old implementation:

  • Input: "line1\n\nline3", prefix " "
  • Old output: " line1\n \n line3" (middle line is " ", two spaces)
  • New output: " line1\n\n line3" (middle line is empty)

The existing TestRenderStringTemplate in internal/provider/template_test.go continues to pass unchanged.

@javabrett
javabrett requested a review from a team as a code owner May 20, 2026 21:35
@hashicorp-cla-app

hashicorp-cla-app Bot commented May 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app

Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

… frontmatter

PrefixLines unconditionally prepended the indent prefix to every line,
including empty strings produced by splitting on blank lines. In YAML
block scalars this created lines containing only spaces ("  ") rather
than genuinely empty lines.

Skip adding the prefix when the line is empty, so blank lines inside a
provider description pass through unchanged.
@javabrett
javabrett force-pushed the fix/prefixlines-blank-line-whitespace branch from 17c2b03 to cdf644a Compare June 2, 2026 00:18
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.

1 participant