diff --git a/src/htmltojsx.js b/src/htmltojsx.js index 3e3ec5d..3d8c28c 100644 --- a/src/htmltojsx.js +++ b/src/htmltojsx.js @@ -610,9 +610,14 @@ HTMLtoJSX.prototype = { * @return {string} */ _getElementAttribute: function(node, attribute) { + var value = attribute.value; + // If there's some newlines in the value, compact it + if ( value.indexOf('\n') > -1 ) { + value = value.replace(/^\s+/mg, ' ').replace(/\n/g, ''); + } switch (attribute.name) { case 'style': - return this._getStyleAttribute(attribute.value); + return this._getStyleAttribute(value); default: var tagName = jsxTagName(node.tagName); var name = @@ -623,10 +628,10 @@ HTMLtoJSX.prototype = { var result = name; // Numeric values should be output as {123} not "123" - if (isNumeric(attribute.value)) { - result += '={' + attribute.value + '}'; - } else if (attribute.value.length > 0) { - result += '="' + attribute.value.replace(/"/gm, '"') + '"'; + if (isNumeric(value)) { + result += '={' + value + '}'; + } else if (value.length > 0) { + result += '="' + value.replace(/"/gm, '"') + '"'; } return result; } diff --git a/test/htmltojsx-test.js b/test/htmltojsx-test.js index e091753..50a9eac 100644 --- a/test/htmltojsx-test.js +++ b/test/htmltojsx-test.js @@ -238,6 +238,17 @@ describe('htmltojsx', function() { expect(converter.convert('').trim()) .toBe(''); }); + + it('should compact multilignes attributes', function() { + var converter = new HTMLtoJSX({ createClass: false }); + expect(converter.convert([ + '
multilignes classes
' + ].join('\n')).trim()) + .toBe('
multilignes classes
'); + }); }); describe('special tags', function() {