8000 Preserve source indentation in nested partials by Aschenbath · Pull Request #132 · noahmorrison/chevron · GitHub
[go: up one dir, main page]

Skip to content

Preserve source indentation in nested partials - #132

Open
Aschenbath wants to merge 1 commit into
noahmorrison:mainfrom
Aschenbath:fix/nested-partial-indentation-20261116
Open

Aschenbath wants to merge 1 commit into
noahmorrison:mainfrom
Aschenbath:fix/nested-partial-indentation-20261116

Conversation

@Aschenbath
Copy link
Copy Markdown

Nested standalone partials count their parent's rendered indentation again at each level, and lines following the partial lose their parent indentation. Preserve each partial tag's original source indentation in a tuple-compatible token, combine it with the parent padding once, and restore the parent padding afterward. Inline partials and empty partials are handled separately so rendered variable values cannot be mistaken for source indentation.

Fixes #100.

Eight regression tests cover the reported three-level template, first-line nesting, tabs and mixed whitespace, missing final newlines, consecutive and empty partials, multiline variables, and pre-tokenized/deep-copied/pickled templates. The full 150-test suite passes on Python 3.8.20, 3.12.12 and 3.14.9; the first five new regressions fail against the original implementation. Older Python versions were not available locally. Flake8 7.5.0 reports the same 17 existing findings on the base and this branch, with no new findings.

A separate comparison with Mustache.js 4.2.0 over 1,440 generated scenarios corrects 840 previously mismatching cases and introduces no mismatches among baseline-correct cases. There are still 174 pre-existing differences, mainly blank-line whitespace; this comparison is not a claim of complete cross-implementation equivalence.

Implemented and tested with OpenAI Codex.

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.

Indentation is not being preserved in nested partials

1 participant

0