Skip to content

Commit

Permalink
fix no more cuts of content prematurely in indentResolve
Browse files Browse the repository at this point in the history
  • Loading branch information
voischev committed Aug 31, 2016
1 parent a5cd82c commit 04399e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 3 additions & 5 deletions index.js
Expand Up @@ -2,15 +2,13 @@
var postcss = require('postcss');

function indentResolve(str, options) {
var strLastIndexOf = str.lastIndexOf('\n');

if (str.match(/\n(?!\n)\s*/g) === null) {
return str;
}

if (options.length === undefined) {
options.lastLine = str.substr(strLastIndexOf + 1);
var newStr = str.substr(0, strLastIndexOf + 1);
options.lastLine = str.substr(str.lastIndexOf('\n') + 1);
var newStr = str.substr(0, str.lastIndexOf('\n') + 1);
options.length = Math.min.apply(Math, newStr.match(/\n(?!\n)\s*/g).filter(function(space) {
return space.length > 2;
}).map(function(space) {
Expand All @@ -25,7 +23,7 @@ function indentResolve(str, options) {
str = str.replace(new RegExp(options.match,'g'), '');
} else {
str = str.replace(/\n/g, '\n' + options.match);
str = str.substr(0, strLastIndexOf + 1) + options.lastLine;
str = str.substr(0, str.lastIndexOf('\n') + 1) + options.lastLine;
}
return str;
}
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Expand Up @@ -56,6 +56,12 @@ describe('use postcss', function() {
test(html, expected, {}, null, done);
});

it('style tag with newline and multyply indent', function(done) {
var html = 'text <style>\n .test {\n color: red;\n}</style>';
var expected = 'text <style>\n .test {\n color: red;\n}</style>';
test(html, expected, {}, null, done);
});

it('style tag with newline and indent', function(done) {
var html = 'text <style>\n .test { color: red; }</style>';
var expected = 'text <style>\n .test { color: red; }</style>';
Expand Down

0 comments on commit 04399e6

Please sign in to comment.