@@ -19,6 +19,8 @@ public class LegacyOverrides {
1919 .withAllowAdjacentTextNodes (true )
2020 .withUseTrimmingForNotesAndExpressions (true )
2121 .withKeepNullableLoopValues (true )
22+ .withHandleBackslashInQuotesOnly (true )
23+ .withDefaultKeepTrailingNewlineBehavior (false )
2224 .build ();
2325 private final boolean evaluateMapKeys ;
2426 private final boolean iterateOverMapKeys ;
@@ -30,6 +32,8 @@ public class LegacyOverrides {
3032 private final boolean allowAdjacentTextNodes ;
3133 private final boolean useTrimmingForNotesAndExpressions ;
3234 private final boolean keepNullableLoopValues ;
35+ private final boolean handleBackslashInQuotesOnly ;
36+ private final boolean defaultKeepTrailingNewlineBehavior ;
3337
3438 private LegacyOverrides (Builder builder ) {
3539 evaluateMapKeys = builder .evaluateMapKeys ;
@@ -42,6 +46,8 @@ private LegacyOverrides(Builder builder) {
4246 allowAdjacentTextNodes = builder .allowAdjacentTextNodes ;
4347 useTrimmingForNotesAndExpressions = builder .useTrimmingForNotesAndExpressions ;
4448 keepNullableLoopValues = builder .keepNullableLoopValues ;
49+ handleBackslashInQuotesOnly = builder .handleBackslashInQuotesOnly ;
50+ defaultKeepTrailingNewlineBehavior = builder .defaultKeepTrailingNewlineBehavior ;
4551 }
4652
4753 public static Builder newBuilder () {
@@ -88,6 +94,19 @@ public boolean isKeepNullableLoopValues() {
8894 return keepNullableLoopValues ;
8995 }
9096
97+ public boolean isHandleBackslashInQuotesOnly () {
98+ return handleBackslashInQuotesOnly ;
99+ }
100+
101+ /**
102+ * The default value of {@link JinjavaConfig#isKeepTrailingNewline()}.
103+ * {@code true} preserves Jinjava's historical behaviour of keeping the trailing newline;
104+ * {@code false} matches Python Jinja2's default of stripping it.
105+ */
106+ public boolean getDefaultKeepTrailingNewlineBehavior () {
107+ return defaultKeepTrailingNewlineBehavior ;
108+ }
109+
91110 public static class Builder {
92111
93112 private boolean evaluateMapKeys = false ;
@@ -100,6 +119,8 @@ public static class Builder {
100119 private boolean allowAdjacentTextNodes = false ;
101120 private boolean useTrimmingForNotesAndExpressions = false ;
102121 private boolean keepNullableLoopValues = false ;
122+ private boolean handleBackslashInQuotesOnly = false ;
123+ private boolean defaultKeepTrailingNewlineBehavior = true ;
103124
104125 private Builder () {}
105126
@@ -123,6 +144,10 @@ public static Builder from(LegacyOverrides legacyOverrides) {
123144 .withAllowAdjacentTextNodes (legacyOverrides .allowAdjacentTextNodes )
124145 .withUseTrimmingForNotesAndExpressions (
125146 legacyOverrides .useTrimmingForNotesAndExpressions
147+ )
148+ .withHandleBackslashInQuotesOnly (legacyOverrides .handleBackslashInQuotesOnly )
149+ .withDefaultKeepTrailingNewlineBehavior (
150+ legacyOverrides .defaultKeepTrailingNewlineBehavior
126151 );
127152 }
128153
@@ -187,5 +212,17 @@ public Builder withKeepNullableLoopValues(boolean keepNullableLoopValues) {
187212 this .keepNullableLoopValues = keepNullableLoopValues ;
188213 return this ;
189214 }
215+
216+ public Builder withHandleBackslashInQuotesOnly (boolean handleBackslashInQuotesOnly ) {
217+ this .handleBackslashInQuotesOnly = handleBackslashInQuotesOnly ;
218+ return this ;
219+ }
220+
221+ public Builder withDefaultKeepTrailingNewlineBehavior (
222+ boolean defaultKeepTrailingNewlineBehavior
223+ ) {
224+ this .defaultKeepTrailingNewlineBehavior = defaultKeepTrailingNewlineBehavior ;
225+ return this ;
226+ }
190227 }
191228}
0 commit comments