File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,13 @@ class MustachioParser {
115
115
}
116
116
} else {
117
117
assert (result.type == _TagParseResultType .parsedTag);
118
- trimTextRight ();
118
+ if (result.node is Section ) {
119
+ // Trim the right off of the preceding text node, only if a Section
120
+ // was just parsed. For other tags, like Variables or Partials,
121
+ // the whitespace may be important, as the tag itself will be
122
+ // rendered as text.
123
+ trimTextRight ();
124
+ }
119
125
addTextNode (textStartIndex, textEndIndex);
120
126
children.add (result.node);
121
127
textStartIndex = _index;
Original file line number Diff line number Diff line change @@ -385,7 +385,8 @@ void main() {
385
385
expect (renderBar (bar, barTemplate), equals ('Text Partial hello' ));
386
386
});
387
387
388
- test ('Parser removes whitespace preceding a tag on its own line' , () async {
388
+ test ('Parser removes whitespace preceding a Section tag on its own line' ,
389
+ () async {
389
390
var fooTemplateFile = getFile ('/project/foo.mustache' )
390
391
..writeAsStringSync ('''
391
392
<ol>
@@ -405,6 +406,25 @@ void main() {
405
406
''' ));
406
407
});
407
408
409
+ test ('Parser does not remove whitespace preceding a non-Section tag' ,
410
+ () async {
411
+ var fooTemplateFile = getFile ('/project/foo.mustache' )
412
+ ..writeAsStringSync ('''
413
+ Hello
414
+ {{ #b1 }}
415
+ {{ s1 }}
416
+ {{ /b1 }}
417
+ ''' );
418
+ var fooTemplate = await Template .parse (fooTemplateFile);
419
+ var foo = Foo ()
420
+ ..b1 = true
421
+ ..s1 = 'World' ;
422
+ expect (renderFoo (foo, fooTemplate), equals ('''
423
+ Hello
424
+ World
425
+ ''' ));
426
+ });
427
+
408
428
test ('Renderer throws when it cannot resolve a variable key' , () async {
409
429
var fooTemplateFile = getFile ('/project/foo.mustache' )
410
430
..writeAsStringSync ('Text {{s2}}' );
You can’t perform that action at this time.
0 commit comments