Skip to content

fix(llm): trim trailing blank lines from the markdown output#82

Merged
markdumay merged 1 commit into
mainfrom
fix/llm-trailing-blank-line
Jun 18, 2026
Merged

fix(llm): trim trailing blank lines from the markdown output#82
markdumay merged 1 commit into
mainfrom
fix/llm-trailing-blank-line

Conversation

@markdumay

Copy link
Copy Markdown
Contributor

Problem

safe-content.html trims only leading newlines (strings.TrimLeft "\n"). Content with trailing blank lines therefore leaves stray blank lines at the end of the generated index.md / llms.txt, which markdownlint flags as MD012 (multiple consecutive blank lines).

This shows up with generated / content-adapter pages and multi-shortcode output — e.g. a JSON-Schema table renderer that emits one {{< schema >}} call per definition: each call's trailing newline plus the join newline accumulate into trailing blanks the wrapper preserves.

Fix

Trim both ends and emit a single final newline:

- {{- $content = strings.TrimLeft "\n" $content -}}
- {{- return $content -}}
+ {{- $content = strings.Trim $content "\n" -}}
+ {{- return (printf "%s\n" $content) -}}

Result: no trailing blank lines (MD012) and a single final newline (MD047). The leading trim is preserved (the caller still controls top-of-content spacing).

Verification

Added exampleSite/content/docs/trailing-blanks.md (a page with trailing blank lines). Before: its index.md ended with …\n\n → MD012. After: ends with a single \n, MD012/MD047 clean. No change to existing pages (getting-started, blog, etc. still end with a single newline).

🤖 Generated with Claude Code

safe-content only trimmed leading newlines, so content with trailing blank
lines (generated/content-adapter pages, or multi-shortcode output such as table
renderers) left stray trailing blanks in the LLM markdown output — flagged by
markdownlint MD012. Trim both ends and emit a single final newline, so the output
has no trailing blank lines (MD012) and ends with one newline (MD047). Adds an
exampleSite fixture that exercises trailing-blank handling.
@markdumay markdumay merged commit 7d49bec into main Jun 18, 2026
8 checks passed
@markdumay

Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 1.3.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@markdumay markdumay deleted the fix/llm-trailing-blank-line branch June 18, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant