From 91051c6a9c66ae3635ef1c88018ad7c369d5dcfd Mon Sep 17 00:00:00 2001 From: Sven Nicolai Viig Date: Sun, 22 Jan 2017 23:05:31 +0100 Subject: [PATCH] Removing jsx class-level indention when transforming HTML into JSX when createClass is set to false in the converter config --- src/htmltojsx.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/htmltojsx.js b/src/htmltojsx.js index 526df91..c48b778 100644 --- a/src/htmltojsx.js +++ b/src/htmltojsx.js @@ -224,6 +224,8 @@ HTMLtoJSX.prototype = { this.output += this.config.indent + this.config.indent + ');\n'; this.output += this.config.indent + '}\n'; this.output += '});'; + } else { + this.output = this._removeJSXClassIndention(this.output, this.config.indent); } return this.output; }, @@ -507,6 +509,19 @@ HTMLtoJSX.prototype = { _getStyleAttribute: function(styles) { var jsxStyles = new StyleParser(styles).toJSXString(); return 'style={{' + jsxStyles + '}}'; + }, + + /** + * Removes class-level indention in the JSX output. To be used when the JSX + * output is configured to not contain a class deifinition. + * + * @param {string} output JSX output with class-level indention + * @param {string} indent Configured indention + * @return {string} JSX output wihtout class-level indention + */ + _removeJSXClassIndention: function(output, indent) { + var classIndention = new RegExp('\\n' + indent + indent + indent, 'g'); + return output.replace(classIndention, '\n'); } };