Skip to content

Commit cf9031c

Browse files
committed
Preserve empty newlines
1 parent 0567f8f commit cf9031c

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

mustache.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,22 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
216216
'\nsend("'
217217
];
218218

219-
var spaces = [], // indices of whitespace in code for the current line
219+
var spaces = [], // indices of whitespace in code on the current line
220+
hasTag = false, // is there a {{tag}} on the current line?
220221
nonSpace = false; // is there a non-space char on the current line?
221222

222223
// Strips all space characters from the code array for the current line
223224
// if there was a {{tag}} on it and otherwise only spaces.
224225
var stripSpace = function () {
225-
if (!nonSpace && !options.space) {
226+
if (hasTag && !nonSpace && !options.space) {
226227
while (spaces.length) {
227228
code.splice(spaces.pop(), 1);
228229
}
229230
} else {
230231
spaces = [];
231232
}
232233

234+
hasTag = false;
233235
nonSpace = false;
234236
};
235237

@@ -330,6 +332,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
330332
updateLine = '\nline = ' + line + ';';
331333
nextOpenTag = openTag;
332334
nextCloseTag = closeTag;
335+
hasTag = true;
333336

334337
switch (c) {
335338
case "!": // comment

spec/_files/recursion_with_same_names.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name
22
desc
3+
34
t1
45
0
56
t2

spec/_files/whitespace.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var whitespace = {
2+
tag1: "Hello",
3+
tag2: "World"
4+
};

spec/_files/whitespace.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{tag1}}
2+
3+
4+
{{tag2}}.

spec/_files/whitespace.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Hello
2+
3+
4+
World.

0 commit comments

Comments
 (0)