@@ -35,6 +35,104 @@ var ELEMENT_ATTRIBUTE_MAPPING = {
35
35
}
36
36
} ;
37
37
38
+ // Reference: https://developer.mozilla.org/en-US/docs/Web/SVG/Element#SVG_elements
39
+ var ELEMENT_TAG_NAME_MAPPING = {
40
+ a : 'a' ,
41
+ altglyph : 'altGlyph' ,
42
+ altglyphdef : 'altGlyphDef' ,
43
+ altglyphitem : 'altGlyphItem' ,
44
+ animate : 'animate' ,
45
+ animatecolor : 'animateColor' ,
46
+ animatemotion : 'animateMotion' ,
47
+ animatetransform : 'animateTransform' ,
48
+ audio : 'audio' ,
49
+ canvas : 'canvas' ,
50
+ circle : 'circle' ,
51
+ clippath : 'clipPath' ,
52
+ color - profile : 'color' ,
53
+ cursor : 'cursor' ,
54
+ defs : 'defs' ,
55
+ desc : 'desc' ,
56
+ discard : 'discard' ,
57
+ ellipse : 'ellipse' ,
58
+ feblend : 'feBlend' ,
59
+ fecolormatrix : 'feColorMatrix' ,
60
+ fecomponenttransfer : 'feComponentTransfer' ,
61
+ fecomposite : 'feComposite' ,
62
+ feconvolvematrix : 'feConvolveMatrix' ,
63
+ fediffuselighting : 'feDiffuseLighting' ,
64
+ fedisplacementmap : 'feDisplacementMap' ,
65
+ fedistantlight : 'feDistantLight' ,
66
+ fedropshadow : 'feDropShadow' ,
67
+ feflood : 'feFlood' ,
68
+ fefunca : 'feFuncA' ,
69
+ fefuncb : 'feFuncB' ,
70
+ fefuncg : 'feFuncG' ,
71
+ fefuncr : 'feFuncR' ,
72
+ fegaussianblur : 'feGaussianBlur' ,
73
+ feimage : 'feImage' ,
74
+ femerge : 'feMerge' ,
75
+ femergenode : 'feMergeNode' ,
76
+ femorphology : 'feMorphology' ,
77
+ feoffset : 'feOffset' ,
78
+ fepointlight : 'fePointLight' ,
79
+ fespecularlighting : 'feSpecularLighting' ,
80
+ fespotlight : 'feSpotLight' ,
81
+ fetile : 'feTile' ,
82
+ feturbulence : 'feTurbulence' ,
83
+ filter : 'filter' ,
84
+ font : 'font' ,
85
+ font - face : 'font' ,
86
+ font - face - format : 'font' ,
87
+ font - face - name : 'font' ,
88
+ font - face - src : 'font' ,
89
+ font - face - uri : 'font' ,
90
+ foreignobject : 'foreignObject' ,
91
+ g : 'g' ,
92
+ glyph : 'glyph' ,
93
+ glyphref : 'glyphRef' ,
94
+ hatch : 'hatch' ,
95
+ hatchpath : 'hatchpath' ,
96
+ hkern : 'hkern' ,
97
+ iframe : 'iframe' ,
98
+ image : 'image' ,
99
+ line : 'line' ,
100
+ lineargradient : 'linearGradient' ,
101
+ marker : 'marker' ,
102
+ mask : 'mask' ,
103
+ mesh : 'mesh' ,
104
+ meshgradient : 'meshgradient' ,
105
+ meshpatch : 'meshpatch' ,
106
+ meshrow : 'meshrow' ,
107
+ metadata : 'metadata' ,
108
+ missing - glyph : 'missing' ,
109
+ mpath : 'mpath' ,
110
+ path : 'path' ,
111
+ pattern : 'pattern' ,
112
+ polygon : 'polygon' ,
113
+ polyline : 'polyline' ,
114
+ radialgradient : 'radialGradient' ,
115
+ rect : 'rect' ,
116
+ script : 'script' ,
117
+ set : 'set' ,
118
+ solidcolor : 'solidcolor' ,
119
+ stop : 'stop' ,
120
+ style : 'style' ,
121
+ svg : 'svg' ,
122
+ switch : 'switch' ,
123
+ symbol : 'symbol' ,
124
+ text : 'text' ,
125
+ textpath : 'textPath' ,
126
+ title : 'title' ,
127
+ tref : 'tref' ,
128
+ tspan : 'tspan' ,
129
+ unknown : 'unknown' ,
130
+ use : 'use' ,
131
+ video : 'video' ,
132
+ view : 'view' ,
133
+ vkern : 'vkern'
134
+ } ;
135
+
38
136
var HTMLDOMPropertyConfig = require ( 'react-dom/lib/HTMLDOMPropertyConfig' ) ;
39
137
var SVGDOMPropertyConfig = require ( 'react-dom/lib/SVGDOMPropertyConfig' ) ;
40
138
@@ -67,6 +165,22 @@ function mappingAttributesFromReactConfig(config) {
67
165
mappingAttributesFromReactConfig ( HTMLDOMPropertyConfig ) ;
68
166
mappingAttributesFromReactConfig ( SVGDOMPropertyConfig ) ;
69
167
168
+ /**
169
+ * Convert tag name to tag name suitable for JSX.
170
+ *
171
+ * @param {string } tagName String of tag name
172
+ * @return {string }
173
+ */
174
+ function jsxTagName ( tagName ) {
175
+ var name = tagName . toLowerCase ( ) ;
176
+
177
+ if ( ELEMENT_TAG_NAME_MAPPING . hasOwnProperty ( name ) ) {
178
+ name = ELEMENT_TAG_NAME_MAPPING [ name ] ;
179
+ }
180
+
181
+ return name ;
182
+ }
183
+
70
184
/**
71
185
* Repeats a string a certain number of times.
72
186
* Also: the future is bright and consists of native string repetition:
@@ -379,7 +493,7 @@ HTMLtoJSX.prototype = {
379
493
* @param {DOMElement } node
380
494
*/
381
495
_beginVisitElement : function ( node ) {
382
- var tagName = node . tagName . toLowerCase ( ) ;
496
+ var tagName = jsxTagName ( node . tagName ) ;
383
497
var attributes = [ ] ;
384
498
for ( var i = 0 , count = node . attributes . length ; i < count ; i ++ ) {
385
499
attributes . push ( this . _getElementAttribute ( node , node . attributes [ i ] ) ) ;
@@ -412,14 +526,14 @@ HTMLtoJSX.prototype = {
412
526
* @param {Node } node
413
527
*/
414
528
_endVisitElement : function ( node ) {
415
- var tagName = node . tagName . toLowerCase ( ) ;
529
+ var tagName = jsxTagName ( node . tagName ) ;
416
530
// De-indent a bit
417
531
// TODO: It's inefficient to do it this way :/
418
532
this . output = trimEnd ( this . output , this . config . indent ) ;
419
533
if ( this . _isSelfClosing ( node ) ) {
420
534
this . output += ' />' ;
421
535
} else {
422
- this . output += '</' + node . tagName . toLowerCase ( ) + '>' ;
536
+ this . output += '</' + tagName + '>' ;
423
537
}
424
538
425
539
if ( tagName === 'pre' ) {
@@ -435,9 +549,10 @@ HTMLtoJSX.prototype = {
435
549
* @return {boolean }
436
550
*/
437
551
_isSelfClosing : function ( node ) {
552
+ var tagName = jsxTagName ( node . tagName ) ;
438
553
// If it has children, it's not self-closing
439
554
// Exception: All children of a textarea are moved to a "defaultValue" attribute, style attributes are dangerously set.
440
- return ! node . firstChild || node . tagName . toLowerCase ( ) === 'textarea' || node . tagName . toLowerCase ( ) === 'style' ;
555
+ return ! node . firstChild || tagName === 'textarea' || tagName === 'style' ;
441
556
} ,
442
557
443
558
/**
@@ -446,7 +561,7 @@ HTMLtoJSX.prototype = {
446
561
* @param {TextNode } node
447
562
*/
448
563
_visitText : function ( node ) {
449
- var parentTag = node . parentNode && node . parentNode . tagName . toLowerCase ( ) ;
564
+ var parentTag = node . parentNode && jsxTagName ( node . parentNode . tagName ) ;
450
565
if ( parentTag === 'textarea' || parentTag === 'style' ) {
451
566
// Ignore text content of textareas and styles, as it will have already been moved
452
567
// to a "defaultValue" attribute and "dangerouslySetInnerHTML" attribute respectively.
@@ -499,7 +614,7 @@ HTMLtoJSX.prototype = {
499
614
case 'style' :
500
615
return this . _getStyleAttribute ( attribute . value ) ;
501
616
default :
502
- var tagName = node . tagName . toLowerCase ( ) ;
617
+ var tagName = jsxTagName ( node . tagName ) ;
503
618
var name =
504
619
( ELEMENT_ATTRIBUTE_MAPPING [ tagName ] &&
505
620
ELEMENT_ATTRIBUTE_MAPPING [ tagName ] [ attribute . name ] ) ||
0 commit comments