Skip to content

Engine: Preserve line count for multi-line code blocks#1556

Open
joelhawksley wants to merge 6 commits intomarcoroth:mainfrom
joelhawksley:fix/multiline-code-block-line-preservation
Open

Engine: Preserve line count for multi-line code blocks#1556
joelhawksley wants to merge 6 commits intomarcoroth:mainfrom
joelhawksley:fix/multiline-code-block-line-preservation

Conversation

@joelhawksley
Copy link
Copy Markdown
Contributor

Multi-line <% ... %> code blocks where <% and %> are on their own lines lose line count parity with Erubi. The .strip call on node.content.value removes the leading/trailing newlines that represent the delimiter lines.

Erubi processes templates line-by-line and naturally emits blank lines for standalone <% and %> delimiters. Herb processes the entire ERBContentNode as one chunk and strips these.

Fix: Detect when raw content starts/ends with newlines (indicating standalone delimiters) and preserve them. Adjust apply_trim to use right_space = "\n" when code already ends with a newline to avoid double-newline emission.

Multi-line `<% ... %>` code blocks where `<%` and `%>` are on their
own lines lose line count parity with Erubi. The `.strip` call on
`node.content.value` removes the leading/trailing newlines that
represent the `<%` and `%>` delimiter lines.

Erubi processes templates line-by-line and naturally emits blank lines
for standalone `<%` and `%>` delimiters. Herb processes the entire
ERBContentNode as one chunk.

Fix: Detect when raw content starts/ends with newlines (indicating
standalone delimiters) and preserve them in the emitted code. Also
adjust `apply_trim` to use `right_space = "\n"` when code already
ends with a newline, avoiding double-newline emission.
@joelhawksley joelhawksley marked this pull request as draft March 31, 2026 16:48
@joelhawksley
Copy link
Copy Markdown
Contributor Author

joelhawksley commented Mar 31, 2026

Moving back to draft mode while I re-validate against 0.9.3.

@joelhawksley joelhawksley marked this pull request as ready for review March 31, 2026 17:17
@marcoroth marcoroth changed the title Preserve line count for multi-line code blocks Engine: Preserve line count for multi-line code blocks Mar 31, 2026
@joelhawksley joelhawksley reopened this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant