Skip to content

Removing jsx class-level indention when transforming HTML into JSX #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/htmltojsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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');
}
};

Expand Down