diff --git a/src/lexical.js b/src/lexical.js index 7e81ebffb..9aa9e1e96 100644 --- a/src/lexical.js +++ b/src/lexical.js @@ -27,7 +27,7 @@ var hash = new RegExp(`(?:${identifier.source})\\s*:\\s*(?:${value.source})`); var hashCapture = new RegExp(`(${identifier.source})\\s*:\\s*(${value.source})`, 'g'); // full match -var tagLine = new RegExp(`^\\s*(${identifier.source})\\s*(.*)\\s*$`); +var tagLine = new RegExp(`^\\s*(${identifier.source})\\s*([\\s\\S]*)\\s*$`); var literalLine = new RegExp(`^${literal.source}$`, 'i'); var variableLine = new RegExp(`^${variable.source}$`); var numberLine = new RegExp(`^${number.source}$`); diff --git a/src/tokenizer.js b/src/tokenizer.js index 9c56c924f..463dfa0f3 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -9,7 +9,7 @@ function parse(html, filepath, options) { html = whiteSpaceCtrl(html, options); var tokens = []; - var syntax = /({%-?(.*?)-?%})|({{(.*?)}})/g; + var syntax = /({%-?([\s\S]*?)-?%})|({{([\s\S]*?)}})/g; var result, htmlFragment, token; var lastMatchEnd = 0, lastMatchBegin = -1, parsedLinesCount = 0; diff --git a/test/tag.js b/test/tag.js index 3d9123606..d7fbf0c67 100644 --- a/test/tag.js +++ b/test/tag.js @@ -62,9 +62,9 @@ describe('tag', function() { }); token = { type: 'tag', - value: 'foo aa:foo bb: arr[0] cc: 2.3 dd:bar.coo', + value: 'foo aa:foo bb: arr[0] cc: 2.3\ndd:bar.coo', name: 'foo', - args: 'aa:foo bb: arr[0] cc: 2.3 dd:bar.coo' + args: 'aa:foo bb: arr[0] cc: 2.3\ndd:bar.coo' }; }); it('should call tag.render with scope', function() { diff --git a/test/tokenizer.js b/test/tokenizer.js index f1f612126..565fac03f 100644 --- a/test/tokenizer.js +++ b/test/tokenizer.js @@ -56,6 +56,21 @@ describe('tokenizer', function() { expect(tokens[3].type).to.equal('html'); expect(tokens[3].raw).to.equal(' \n '); }); + it('should handle multiple lines tag', function() { + var html = '{%foo\na:a\nb:1.23\n%}'; + var tokens = parse(html); + expect(tokens.length).to.equal(1); + expect(tokens[0].type).to.equal('tag'); + expect(tokens[0].args).to.equal('a:a\nb:1.23'); + expect(tokens[0].raw).to.equal('{%foo\na:a\nb:1.23\n%}'); + }); + it('should handle multiple lines output', function() { + var html = '{{foo\n|\date:\n"%Y-%m-%d"\n}}'; + var tokens = parse(html); + expect(tokens.length).to.equal(1); + expect(tokens[0].type).to.equal('output'); + expect(tokens[0].raw).to.equal('{{foo\n|\date:\n"%Y-%m-%d"\n}}'); + }); }); describe('whitespace control', function() { it('should not strip by default', function() {