Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Merge pull request #534 from janka102/fix-#526
Browse files Browse the repository at this point in the history
Fixed spaceless tag stripping too much (#526)
  • Loading branch information
paularmstrong committed Oct 31, 2014
2 parents 73cb7c1 + f89b78e commit 90ac5cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
18 changes: 5 additions & 13 deletions lib/tags/spaceless.js
Expand Up @@ -15,20 +15,12 @@ var utils = require('../utils');
*
*/
exports.compile = function (compiler, args, content, parents, options, blockName) {
function stripWhitespace(tokens) {
return utils.map(tokens, function (token) {
if (token.content || typeof token !== 'string') {
token.content = stripWhitespace(token.content);
return token;
}
var out = compiler(content, parents, options, blockName);
out += '_output = _output.replace(/^\\s+/, "")\n' +
' .replace(/>\\s+</g, "><")\n' +
' .replace(/\\s+$/, "");\n';

return token.replace(/^\s+/, '')
.replace(/>\s+</g, '><')
.replace(/\s+$/, '');
});
}

return compiler(stripWhitespace(content), parents, options, blockName);
return out;
};

exports.parse = function (str, line, parser) {
Expand Down
4 changes: 2 additions & 2 deletions tests/tags/spaceless.test.js
Expand Up @@ -7,8 +7,8 @@ var cases = [
{ c: '{% spaceless %} <p> foo </p> <p>bar</p> {% endspaceless %}', e: '<p> foo </p><p>bar</p>' },
{ c: '{% spaceless %}{% if true %}<p></p> <p></p>{% endif %}{% endspaceless %}', e: '<p></p><p></p>' },
{ c: '{% spaceless %}{% if false %}{% else %}<p></p> <p></p>{% endif %}{% endspaceless %}', e: '<p></p><p></p>' },
{ c: '{% spaceless %}{% macro foo %}<p></p> <p></p>{% endmacro %}{% endspaceless %}{{ foo() }}', e: '<p></p><p></p>' },
{ c: '{% macro foo %}<p></p> <p></p>{% endmacro %}{% spaceless %}{{ foo() }}{% endspaceless %}', e: '<p></p> <p></p>' }
{ c: '{% spaceless %}{% macro foo %}<p></p> <p></p>{% endmacro %}{% endspaceless %}{{ foo() }}', e: '<p></p> <p></p>' },
{ c: '{% macro foo %}<p></p> <p></p>{% endmacro %}{% spaceless %}{{ foo() }}{% endspaceless %}', e: '<p></p><p></p>' }
];

describe('Tag: spaceless', function () {
Expand Down

0 comments on commit 90ac5cc

Please sign in to comment.