Skip to content

fix(py/handlebars): keep spaces between tags that share a line - #637

Open
huangjeff5 wants to merge 2 commits into
mainfrom
jeff/hb-inline-space
Open

huangjeff5 wants to merge 2 commits into
mainfrom
jeff/hb-inline-space

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

A block, partial, or comment tag at the start of a line dropped the spaces between it and the next tag on that line, so words in a rendered prompt ran together. Handlebars.js keeps those spaces, and now this engine does too.

from dotpromptz_handlebars import Handlebars

render = Handlebars().compile('Ingredients:\n{{#each items}} {{this}}{{/each}}')
render({'items': ['flour', 'eggs']})
# before: 'Ingredients:\nfloureggs'
# after:  'Ingredients:\n flour eggs'

Decisions

  • Only spaces that run into another tag on the same line are kept. A tag alone on its line still drops that line, including a closing tag on the last line followed by trailing spaces.
  • Same fix for {{#if}}, {{#each}}, {{else}}, closing tags, {{> partial}}, and {{! comment}}, since they all follow the same line rule.

Verification

  • Verified byte-for-byte parity against handlebars@4.7.9: all 8 new cases ({{#each}}, {{#if}}, {{else}}, closing tags, {{> partial}}, {{! comment}}, and trailing spaces after a standalone closing tag at EOF) live in python/handlebars/tests/conformance_cases.json, which test_recorded_output_still_matches_handlebars_4_7_9 re-renders through Node via conformance_oracle.js in CI.

This branch has not been deployed

No deployments
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