diff --git a/src/twig.filters.js b/src/twig.filters.js index abafea6d..fe7ad6f5 100644 --- a/src/twig.filters.js +++ b/src/twig.filters.js @@ -799,6 +799,9 @@ module.exports = function (Twig) { } return Math[method](value * (10 ** precision)) / (10 ** precision); + }, + spaceless(value) { + return value.replace(/>\s+<').trim(); } }; diff --git a/test/test.filters.js b/test/test.filters.js index 2bbbdeb4..f839e6cf 100644 --- a/test/test.filters.js +++ b/test/test.filters.js @@ -769,6 +769,13 @@ describe('Twig.js Filters ->', function () { }); }); + describe('spaceless ->', function () { + it('should spaceless', function () { + const testTemplate = twig({data: '{{ \'
\n b i\n
\'|spaceless }}'}); + testTemplate.render().should.equal('
bi
'); + }); + }); + it('should chain', function () { const testTemplate = twig({data: '{{ ["a", "b", "c"]|keys|reverse }}'}); testTemplate.render().should.equal('2,1,0');