Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js |
— | — | @@ -279,10 +279,15 @@ |
280 | 280 | this.manager.env.dp( 'TemplateHandler._onEnd' + JSON.stringify( tplExpandData.resultTokens ) ); |
281 | 281 | tplExpandData.expandDone = true; |
282 | 282 | var res = tplExpandData.resultTokens; |
283 | | - // Remove 'end' token from end |
284 | | - if ( res.length && res[res.length - 1].type === 'END' ) { |
285 | | - this.manager.env.dp( 'TemplateHandler, stripping end ' ); |
| 283 | + // Strip 'end' tokens and trailing newlines |
| 284 | + var l = res[res.length - 1]; |
| 285 | + while ( res.length && |
| 286 | + ( l.type === 'END' || l.constructor === NlTk ) |
| 287 | + ) |
| 288 | + { |
| 289 | + this.manager.env.dp( 'TemplateHandler, stripping end or whitespace tokens' ); |
286 | 290 | res.pop(); |
| 291 | + l = res[res.length - 1]; |
287 | 292 | } |
288 | 293 | |
289 | 294 | // Could also encapsulate the template tokens here, if that turns out |