@@ -11,6 +11,7 @@ var canTextBeChildOfNode = utilities.canTextBeChildOfNode;
1111 * @param {DomElement[] } nodes - DOM nodes.
1212 * @param {object } [options={}] - Options.
1313 * @param {Function } [options.replace] - Replacer.
14+ * @param {Function } [options.transform] - Transform.
1415 * @param {object } [options.library] - Library (React, Preact, etc.).
1516 * @returns - String or JSX element(s).
1617 */
@@ -26,6 +27,7 @@ function domToReact(nodes, options) {
2627 var node ;
2728 var isWhitespace ;
2829 var hasReplace = typeof options . replace === 'function' ;
30+ var transform = options . transform || utilities . returnFirstArg ;
2931 var replaceElement ;
3032 var props ;
3133 var children ;
@@ -46,7 +48,7 @@ function domToReact(nodes, options) {
4648 key : replaceElement . key || i
4749 } ) ;
4850 }
49- result . push ( replaceElement ) ;
51+ result . push ( transform ( replaceElement , node , i ) ) ;
5052 continue ;
5153 }
5254 }
@@ -68,7 +70,7 @@ function domToReact(nodes, options) {
6870
6971 // We have a text node that's not whitespace and it can be nested
7072 // in its parent so add it to the results
71- result . push ( node . data ) ;
73+ result . push ( transform ( node . data , node , i ) ) ;
7274 continue ;
7375 }
7476
@@ -115,7 +117,7 @@ function domToReact(nodes, options) {
115117 props . key = i ;
116118 }
117119
118- result . push ( createElement ( node . name , props , children ) ) ;
120+ result . push ( transform ( createElement ( node . name , props , children ) , node , i ) ) ;
119121 }
120122
121123 return result . length === 1 ? result [ 0 ] : result ;
0 commit comments