Skip to content

Commit

Permalink
Add CSS Variables support. Fixes GrapesJS#271
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 4, 2017
1 parent ab7ffe1 commit 5b3187b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/parser/model/ParserCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ module.exports = config => ({
// Create style object from the big one
var stl = node.style;
var style = {};

for (var j = 0, len2 = stl.length; j < len2; j++) {
var propName = stl[j];
//console.log('Style', stl, propName, ': ', stl.getPropertyValue(propName));
var important = stl.getPropertyPriority(propName);
style[propName] = stl[propName] +
(important ? ' !' + important : '');
const propName = stl[j];
const propValue = stl.getPropertyValue(propName);
const important = stl.getPropertyPriority(propName);
style[propName] = `${propValue}${important ? ` !${important}` : ''}`
}

var lastRule = '';
Expand Down
16 changes: 16 additions & 0 deletions test/specs/parser/model/ParserCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ module.exports = {
expect(obj.parse(str)).toEqual(result)
});

it('Parse rule with CSS variables', () => {
var str = `:root {
--some-color: red;
--some-width: 55px;
}`;
var result = {
selectors: [],
selectorsAdd: ':root',
style: {
'--some-color': 'red',
'--some-width': '55px',
}
};
expect(obj.parse(str)).toEqual(result)
});

});

}
Expand Down

0 comments on commit 5b3187b

Please sign in to comment.