@@ -5,11 +5,11 @@ var svg = require('property-information/svg')
55var find = require ( 'property-information/find' )
66var spaces = require ( 'space-separated-tokens' )
77var commas = require ( 'comma-separated-tokens' )
8+ var style = require ( 'style-to-object' )
89var ns = require ( 'web-namespaces' )
910var is = require ( 'unist-util-is' )
1011
1112var dashes = / - ( [ a - z ] ) / g
12- var ws = / ^ \s * | \s * $ / g
1313
1414module . exports = wrapper
1515
@@ -80,13 +80,13 @@ function toH(h, node, ctx) {
8080 var value
8181 var result
8282
83- if ( parentSchema . space === 'html' && lower ( name ) === 'svg' ) {
83+ if ( parentSchema . space === 'html' && name . toLowerCase ( ) === 'svg' ) {
8484 schema = svg
8585 ctx . schema = schema
8686 }
8787
8888 if ( ctx . vdom === true && schema . space === 'html' ) {
89- name = upper ( name )
89+ name = name . toUpperCase ( )
9090 }
9191
9292 properties = node . properties
@@ -101,7 +101,7 @@ function toH(h, node, ctx) {
101101 ( ctx . vdom === true || ctx . react === true )
102102 ) {
103103 // VDOM and React accept `style` as object.
104- attributes . style = parseStyle ( attributes . style )
104+ attributes . style = parseStyle ( attributes . style , name )
105105 }
106106
107107 if ( ctx . prefix ) {
@@ -202,25 +202,21 @@ function vdom(h) {
202202 return h && h ( 'div' ) . type === 'VirtualNode'
203203}
204204
205- function parseStyle ( value ) {
205+ function parseStyle ( value , tagName ) {
206206 var result = { }
207- var declarations = value . split ( ';' )
208- var length = declarations . length
209- var index = - 1
210- var declaration
211- var prop
212- var pos
213207
214- while ( ++ index < length ) {
215- declaration = declarations [ index ]
216- pos = declaration . indexOf ( ':' )
217- if ( pos !== - 1 ) {
218- prop = styleCase ( trim ( declaration . slice ( 0 , pos ) ) )
219- result [ prop ] = trim ( declaration . slice ( pos + 1 ) )
220- }
208+ try {
209+ style ( value , iterator )
210+ } catch ( err ) {
211+ err . message = tagName + '[style]' + err . message . slice ( 'undefined' . length )
212+ throw err
221213 }
222214
223215 return result
216+
217+ function iterator ( name , value ) {
218+ result [ styleCase ( name ) ] = value
219+ }
224220}
225221
226222function styleCase ( val ) {
@@ -232,17 +228,5 @@ function styleCase(val) {
232228}
233229
234230function styleReplacer ( $0 , $1 ) {
235- return upper ( $1 )
236- }
237-
238- function lower ( value ) {
239- return value . toLowerCase ( )
240- }
241-
242- function upper ( value ) {
243- return value . toUpperCase ( )
244- }
245-
246- function trim ( value ) {
247- return value . replace ( ws , '' )
231+ return $1 . toUpperCase ( )
248232}
0 commit comments