File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -142,14 +142,16 @@ def format_template_content(template_content):
142142
143143 i += 1
144144
145- # Clean up leading and trailing empty lines that would change output
145+ # Clean up trailing newlines and spaces
146146 result = result .rstrip ()
147147
148- # But preserve the exact trailing newline behavior of the original
149- if template_content .endswith ("\n " ) and not result .endswith ("\n " ):
150- result += "\n "
151- elif not template_content .endswith ("\n " ) and result .endswith ("\n " ):
152- result = result [:- 1 ]
148+ # Copy the newline / space count from the original
149+ tc_rstrip = template_content .rstrip ()
150+ if not tc_rstrip .endswith ("-%}" ) and not tc_rstrip .endswith (r'-}}' ):
151+ # If orig ends with -%} or -}}, that means all newlines are stripped anyways
152+ # So we shouldn't add anything
153+ trailing_length = len (template_content ) - len (tc_rstrip )
154+ result += template_content [:- trailing_length ]
153155
154156 return result
155157
You can’t perform that action at this time.
0 commit comments