Skip to content

Commit 91051c6

Browse files
committed
Removing jsx class-level indention when transforming HTML into JSX when createClass is set to false in the converter config
1 parent 94e39ef commit 91051c6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/htmltojsx.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ HTMLtoJSX.prototype = {
224224
this.output += this.config.indent + this.config.indent + ');\n';
225225
this.output += this.config.indent + '}\n';
226226
this.output += '});';
227+
} else {
228+
this.output = this._removeJSXClassIndention(this.output, this.config.indent);
227229
}
228230
return this.output;
229231
},
@@ -507,6 +509,19 @@ HTMLtoJSX.prototype = {
507509
_getStyleAttribute: function(styles) {
508510
var jsxStyles = new StyleParser(styles).toJSXString();
509511
return 'style={{' + jsxStyles + '}}';
512+
},
513+
514+
/**
515+
* Removes class-level indention in the JSX output. To be used when the JSX
516+
* output is configured to not contain a class deifinition.
517+
*
518+
* @param {string} output JSX output with class-level indention
519+
* @param {string} indent Configured indention
520+
* @return {string} JSX output wihtout class-level indention
521+
*/
522+
_removeJSXClassIndention: function(output, indent) {
523+
var classIndention = new RegExp('\\n' + indent + indent + indent, 'g');
524+
return output.replace(classIndention, '\n');
510525
}
511526
};
512527

0 commit comments

Comments
 (0)