Files
transform/patches/htmltojsx+0.3.0.patch
Ritesh Kumar d2ee2181b0 Improvements in html to JSX transformer (#253)
* partially fixes #252

* use fragments

* fixes

* changes

* changes

* fixes
2020-11-10 13:59:50 +05:30

47 lines
1.9 KiB
Diff

diff --git a/node_modules/htmltojsx/src/htmltojsx.js b/node_modules/htmltojsx/src/htmltojsx.js
index afe4c85..b326beb 100644
--- a/node_modules/htmltojsx/src/htmltojsx.js
+++ b/node_modules/htmltojsx/src/htmltojsx.js
@@ -326,19 +326,9 @@ HTMLtoJSX.prototype = {
convert: function(html) {
this.reset();
- var containerEl = createElement('div');
+ var containerEl = createElement('null');
containerEl.innerHTML = '\n' + this._cleanInput(html) + '\n';
- if (this.config.createClass) {
- if (this.config.outputClassName) {
- this.output = 'var ' + this.config.outputClassName + ' = React.createClass({\n';
- } else {
- this.output = 'React.createClass({\n';
- }
- this.output += this.config.indent + 'render: function() {' + "\n";
- this.output += this.config.indent + this.config.indent + 'return (\n';
- }
-
if (this._onlyOneTopLevel(containerEl)) {
// Only one top-level element, the component can return it directly
// No need to actually visit the container element
@@ -351,13 +341,14 @@ HTMLtoJSX.prototype = {
this._visit(containerEl);
}
this.output = this.output.trim() + '\n';
- if (this.config.createClass) {
- 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);
+ this.output = this._removeJSXClassIndention(this.output, this.config.indent);
+
+ if (this.output.trim().startsWith("{") || this.output.trim().endsWith("}")) {
+ this.output = `<>\n${this.output}</>`
+ } else if (this.output.trim().startsWith("<null>") && this.output.trim().endsWith("</null>")) {
+ this.output = this.output.replace("<null>", "<>").replace("</null>", "</>")
}
+
return this.output;
},