Skip to content

Commit

Permalink
Merge pull request #1539 from aausch/correct_tag_trimming
Browse files Browse the repository at this point in the history
Correct tag trimming
  • Loading branch information
漩涡 committed Oct 9, 2015
2 parents 534102e + ea0e2cb commit cd0d987
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/extend/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ NunjucksBlock.prototype.run = function(context, args, body) {
};

function trimBody(body) {
return stripIndent(body()).trim();
return stripIndent(body()).replace(/^\n?|\n?$/g, '');
}

function NunjucksAsyncTag(name, fn) {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/tag/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function(ctx) {
caption = '<span>' + match[1] + '</span>';
}

content = stripIndent(content).trim();
content = stripIndent(content);

content = highlight(content, {
lang: lang,
Expand Down
13 changes: 13 additions & 0 deletions test/scripts/tags/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ describe('code', function() {
result.should.eql(highlight(fixture));
});

it('non standard indent', function() {
var nonStandardIndent = [
' ',
' return x;',
'}',
'',
fixture,
' '
].join('/n');
var result = code('', nonStandardIndent);
result.should.eql(highlight(nonStandardIndent));
});

it('lang', function() {
var result = code('lang:js', fixture);
result.should.eql(highlight(fixture, {lang: 'js'}));
Expand Down

0 comments on commit cd0d987

Please sign in to comment.