Repository navigation
Preserve source indentation in nested partials - #132
Open
Aschenbath wants to merge 1 commit into
Open
Aschenbath wants to merge 1 commit into
Aschenbath wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.