Skip to content

Commit 4a100dd

Browse files
committed
Merge branch 'dev'
2 parents 246ea1c + f5d0db1 commit 4a100dd

File tree

3 files changed

+9
-33
lines changed

3 files changed

+9
-33
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.gitignore
22
.eslintrc
3+
.travis.yml
34
node_modules/
45
npm-debug.log
56
/lib/*.es6

lib/helpers.es6

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import objectAssign from 'object-assign';
22
import specificity from 'specificity';
3+
import parseAttrs from 'posthtml-attrs-parser';
34

45

56
export function extendStyle(htmlNode, cssNode) {
6-
htmlNode.attrs = htmlNode.attrs || {};
7-
htmlNode.attrs.style = htmlNode.attrs.style || '';
8-
9-
const htmlNodeCss = parseCssFromStyle(htmlNode.attrs.style);
7+
var attrs = parseAttrs(htmlNode.attrs);
108
const cssNodeCss = parseCssFromNode(cssNode);
11-
const newCss = objectAssign({}, htmlNodeCss, cssNodeCss);
12-
htmlNode.attrs.style = stringifyCss(newCss);
9+
attrs.style = objectAssign(attrs.style || {}, cssNodeCss);
10+
htmlNode.attrs = attrs.compose();
1311

1412
return htmlNode;
1513
}
@@ -63,30 +61,6 @@ function getSpecificity(selector) {
6361
}
6462

6563

66-
function stringifyCss(css) {
67-
const styles = Object.keys(css).map(prop => prop + ': ' + css[prop]);
68-
return styles.join('; ');
69-
}
70-
71-
72-
function parseCssFromStyle(style) {
73-
var css = {};
74-
style.split(';').forEach(cssRule => {
75-
const cssRuleParts = cssRule.split(':');
76-
if (cssRuleParts.length < 2) {
77-
return;
78-
}
79-
80-
const cssRuleProp = cssRuleParts[0].trim();
81-
const cssRuleValue = cssRuleParts.slice(1).join(':').trim();
82-
83-
css[cssRuleProp] = cssRuleValue;
84-
});
85-
86-
return css;
87-
}
88-
89-
9064
function parseCssFromNode(cssNode) {
9165
var css = {};
9266
cssNode.nodes.forEach(node => {

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"scripts": {
99
"compile": "rm -f lib/*.js && node_modules/.bin/babel -d lib/ lib/",
1010
"lint": "node_modules/.bin/eslint *.js lib/*.es6 test/",
11-
"pretest": "npm run lint",
12-
"test": "node_modules/.bin/_mocha --compilers js:babel-core/register",
11+
"pretest": "npm run lint && npm run compile",
12+
"test": "node_modules/.bin/_mocha --compilers js:babel-core/register --check-leaks",
1313
"prepublish": "npm run compile"
1414
},
1515
"keywords": [
@@ -30,6 +30,7 @@
3030
"dependencies": {
3131
"object-assign": "^4.0.1",
3232
"postcss": "^5.0.12",
33+
"posthtml-attrs-parser": "^0.1.0",
3334
"posthtml-match-helper": "^1.0.1",
3435
"specificity": "^0.1.4"
3536
},
@@ -42,7 +43,7 @@
4243
"expect": "^1.13.0",
4344
"lodash": "^3.10.1",
4445
"mocha": "^2.3.4",
45-
"posthtml": "^0.7.0"
46+
"posthtml": "^0.8.0"
4647
},
4748
"repository": {
4849
"type": "git",

0 commit comments

Comments
 (0)