File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -610,9 +610,14 @@ HTMLtoJSX.prototype = {
610
610
* @return {string }
611
611
*/
612
612
_getElementAttribute : function ( node , attribute ) {
613
+ var value = attribute . value ;
614
+ // If there's some newlines in the value, compact it
615
+ if ( value . indexOf ( '\n' ) > - 1 ) {
616
+ value = value . replace ( / ^ \s + / mg, ' ' ) . replace ( / \n / g, '' ) ;
617
+ }
613
618
switch ( attribute . name ) {
614
619
case 'style' :
615
- return this . _getStyleAttribute ( attribute . value ) ;
620
+ return this . _getStyleAttribute ( value ) ;
616
621
default :
617
622
var tagName = jsxTagName ( node . tagName ) ;
618
623
var name =
@@ -623,10 +628,10 @@ HTMLtoJSX.prototype = {
623
628
var result = name ;
624
629
625
630
// Numeric values should be output as {123} not "123"
626
- if ( isNumeric ( attribute . value ) ) {
627
- result += '={' + attribute . value + '}' ;
628
- } else if ( attribute . value . length > 0 ) {
629
- result += '="' + attribute . value . replace ( / " / gm, '"' ) + '"' ;
631
+ if ( isNumeric ( value ) ) {
632
+ result += '={' + value + '}' ;
633
+ } else if ( value . length > 0 ) {
634
+ result += '="' + value . replace ( / " / gm, '"' ) + '"' ;
630
635
}
631
636
return result ;
632
637
}
Original file line number Diff line number Diff line change @@ -238,6 +238,17 @@ describe('htmltojsx', function() {
238
238
expect ( converter . convert ( '<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" fill-rule="evenodd"/></svg>' ) . trim ( ) )
239
239
. toBe ( '<svg height={100} width={100}><circle cx={50} cy={50} r={40} stroke="black" strokeWidth={3} fill="red" fillRule="evenodd" /></svg>' ) ;
240
240
} ) ;
241
+
242
+ it ( 'should compact multilignes attributes' , function ( ) {
243
+ var converter = new HTMLtoJSX ( { createClass : false } ) ;
244
+ expect ( converter . convert ( [
245
+ '<div class="cc1' ,
246
+ ' cc2' ,
247
+ ' cc3' ,
248
+ ' cc4">multilignes classes</div>'
249
+ ] . join ( '\n' ) ) . trim ( ) )
250
+ . toBe ( '<div className="cc1 cc2 cc3 cc4">multilignes classes</div>' ) ;
251
+ } ) ;
241
252
} ) ;
242
253
243
254
describe ( 'special tags' , function ( ) {
You can’t perform that action at this time.
0 commit comments