4
4
* Module dependencies.
5
5
*/
6
6
var React = require ( 'react' ) ;
7
+ var attributesToProps = require ( './attributes-to-props' ) ;
7
8
8
9
/**
9
10
* Convert DOM nodes to React elements.
@@ -14,6 +15,7 @@ var React = require('react');
14
15
function domToReact ( nodes ) {
15
16
var result = [ ] ;
16
17
var node ;
18
+ var props ;
17
19
var children ;
18
20
19
21
for ( var i = 0 , len = nodes . length ; i < len ; i ++ ) {
@@ -24,40 +26,38 @@ function domToReact(nodes) {
24
26
continue ;
25
27
}
26
28
29
+ // update values
30
+ props = attributesToProps ( node . attribs ) ;
27
31
children = null ;
28
32
29
33
// node type for script is "script" not "tag"
30
34
if ( node . name === 'script' && node . children [ 0 ] ) {
31
35
// prevent text in script tag from being escaped
32
36
// https://facebook.github.io/react/tips/dangerously-set-inner-html.html
33
- node . attribs . dangerouslySetInnerHTML = {
37
+ props . dangerouslySetInnerHTML = {
34
38
__html : node . children [ 0 ] . data
35
39
} ;
36
40
37
41
} else if ( node . type === 'tag' ) {
38
42
// setting textarea value in children is an antipattern in React
39
43
// https://facebook.github.io/react/docs/forms.html#why-textarea-value
40
44
if ( node . name === 'textarea' && node . children [ 0 ] ) {
41
- node . attribs . defaultValue = node . children [ 0 ] . data ;
45
+ props . defaultValue = node . children [ 0 ] . data ;
42
46
43
47
} else if ( node . children ) {
44
48
// continue recursion of creating React elements
45
- children = domToReact ( node . children ) ;
49
+ children = domToReact ( node . children , options ) ;
46
50
}
47
51
}
48
52
49
53
// specify a `key` prop if returning an array
50
54
// https://fb.me/react-warning-keys
51
55
if ( len > 1 ) {
52
- node . attribs . key = i ;
56
+ props . key = i ;
53
57
}
54
58
55
59
result . push (
56
- React . createElement (
57
- node . name ,
58
- node . attribs ,
59
- children
60
- )
60
+ React . createElement ( node . name , props , children )
61
61
) ;
62
62
}
63
63
0 commit comments