posthtml-postcss
Advanced tools
Comparing version 0.2.0 to 0.2.1
35
index.js
/* global Promise */ | ||
var postcss = require('postcss'); | ||
function indentResolve(str, options) { | ||
if (options.length === undefined) { | ||
if (str.match(/\n(?!\n)\s*/g) === null) { | ||
return str; | ||
} | ||
options.lastLine = str.substr(str.lastIndexOf('\n') + 1); | ||
str = str.substr(0, str.lastIndexOf('\n') + 1); | ||
options.length = Math.min.apply(Math, str.match(/\n(?!\n)\s*/g).filter(function(space) { | ||
return space.length > 2; | ||
}).map(function(space) { | ||
return space.length; | ||
})); | ||
options.match = new Array(options.length).join(' '); | ||
str = str.replace(new RegExp(options.match,'g'), ''); | ||
} else { | ||
str = str.replace(/\n/g, '\n' + options.match); | ||
str = str.substr(0, str.lastIndexOf('\n') + 1) + options.lastLine; | ||
} | ||
return str; | ||
} | ||
module.exports = function(plugins, options) { | ||
@@ -14,8 +37,14 @@ plugins = [].concat(plugins); | ||
tree.walk(function(node) { | ||
var promise; | ||
var promise, | ||
indent = { | ||
length: undefined, | ||
match: '', | ||
lastLine: '' | ||
}; | ||
if (node.tag === 'style' && node.content) { | ||
promise = css.process([].concat(node.content).join(''), options) | ||
var styles = indentResolve([].concat(node.content).join(''), indent); | ||
promise = css.process(styles, options) | ||
.then(function(result) { | ||
node.content = result.css; | ||
node.content = indentResolve(result.css, indent); | ||
}); | ||
@@ -22,0 +51,0 @@ |
{ | ||
"name": "posthtml-postcss", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "PostHTML-PostCSS plugin. Use PostCSS in HTML document.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
6016
57
1