Skip to content

Commit 442166c

Browse files
committed
Remove support for style
1 parent faadb6e commit 442166c

File tree

5 files changed

+13
-41
lines changed

5 files changed

+13
-41
lines changed

example.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var tree = h('.foo#some-id', [
1010
}),
1111
h('a.alpha', {
1212
'class': 'bravo charlie',
13-
'style': 'color:/*red*/purple',
1413
'download': 'download'
1514
}, ['delta', 'echo'])
1615
]);

index.js

+9-22
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
var parseSelector = require('hast-util-parse-selector');
1919
var camelcase = require('camelcase');
2020
var propertyInformation = require('property-information');
21-
var cssDeclarations = require('css-declarations').parse;
2221
var spaces = require('space-separated-tokens').parse;
2322
var commas = require('comma-separated-tokens').parse;
2423

@@ -89,29 +88,20 @@ function addProperty(properties, name, value) {
8988
return;
9089
}
9190

92-
/*
93-
* Handle values.
94-
*/
95-
91+
/* Handle values. */
9692
if (name === 'style') {
97-
/*
98-
* Accept both `string` and `object`.
99-
*/
100-
101-
if (typeof value === 'string') {
102-
result = cssDeclarations(result);
103-
} else {
104-
result = {};
93+
/* Accept `object`. */
94+
if (typeof value !== 'string') {
95+
result = [];
10596

10697
for (key in value) {
107-
result[key] = value[key];
98+
result.push([key, value[key]].join(': '));
10899
}
100+
101+
result = result.join('; ');
109102
}
110103
} else if (info.spaceSeparated) {
111-
/*
112-
* Accept both `string` and `Array`.
113-
*/
114-
104+
/* Accept both `string` and `Array`. */
115105
result = typeof value === 'string' ? spaces(result) : result;
116106

117107
/*
@@ -123,10 +113,7 @@ function addProperty(properties, name, value) {
123113
result = properties.className.concat(result);
124114
}
125115
} else if (info.commaSeparated) {
126-
/*
127-
* Accept both `string` and `Array`.
128-
*/
129-
116+
/* Accept both `string` and `Array`. */
130117
result = typeof value === 'string' ? commas(result) : result;
131118
}
132119

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"dependencies": {
2929
"camelcase": "^3.0.0",
3030
"comma-separated-tokens": "^1.0.0",
31-
"css-declarations": "^1.0.0",
3231
"hast-util-parse-selector": "^2.0.0",
3332
"property-information": "^3.0.0",
3433
"space-separated-tokens": "^1.0.0"

readme.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var tree = h('.foo#some-id', [
3333
}),
3434
h('a.alpha', {
3535
'class': 'bravo charlie',
36-
'style': 'color:/*red*/purple',
3736
'download': 'download'
3837
}, ['delta', 'echo'])
3938
]);
@@ -56,10 +55,7 @@ Yields:
5655
children: [] },
5756
{ type: 'element',
5857
tagName: 'a',
59-
properties:
60-
{ className: [ 'alpha', 'bravo', 'charlie' ],
61-
style: { color: 'purple' },
62-
download: true },
58+
properties: { className: [ 'alpha', 'bravo', 'charlie' ], download: true },
6359
children:
6460
[ { type: 'text', value: 'delta' },
6561
{ type: 'text', value: 'echo' } ] } ] }
@@ -81,9 +77,6 @@ DSL for creating virtual [HAST][] trees.
8177
* `properties` (`Object.<string, *>`, optional)
8278
— Map of properties;
8379

84-
When providing an object to `properties.style`,
85-
make sure you camel-case those properties.
86-
8780
* `children` (`string`, `Node`, `Array.<string|Node>`, optional)
8881
— (List of) child nodes, when strings are encountered,
8982
they are normalised to [`text`][text] nodes.

test.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,14 @@ test('hastscript', function (t) {
419419
h(null, {
420420
'style': {
421421
'color': 'red',
422-
'webkitBorderRadius': '3px'
422+
'-webkit-border-radius': '3px'
423423
}
424424
}),
425425
{
426426
'type': 'element',
427427
'tagName': 'div',
428428
'properties': {
429-
'style': {
430-
'color': 'red',
431-
'webkitBorderRadius': '3px'
432-
}
429+
'style': 'color: red; -webkit-border-radius: 3px'
433430
},
434431
'children': []
435432
},
@@ -444,10 +441,7 @@ test('hastscript', function (t) {
444441
'type': 'element',
445442
'tagName': 'div',
446443
'properties': {
447-
'style': {
448-
'color': 'purple',
449-
'webkitBorderRadius': '3px'
450-
}
444+
'style': 'color:/*red*/purple; -webkit-border-radius: 3px'
451445
},
452446
'children': []
453447
},

0 commit comments

Comments
 (0)