Files
transform/patches/htmltojsx+0.3.0.patch
Ritesh Kumar 190cd96066 🐛 (html-to-jsx) remove semicolon at start and keep empty prop values (#321)
* fixes #310

* 🐛 (html-to-jsx) remove semicolon at start and keep empty prop values

Closes #279, closes #319
2022-01-26 11:47:02 +05:30

56 lines
2.2 KiB
Diff

diff --git a/node_modules/htmltojsx/src/htmltojsx.js b/node_modules/htmltojsx/src/htmltojsx.js
index afe4c85..960e450 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;
},
@@ -627,6 +618,8 @@ HTMLtoJSX.prototype = {
result += '={' + attribute.value + '}';
} else if (attribute.value.length > 0) {
result += '="' + attribute.value.replace(/"/gm, '&quot;') + '"';
+ } else {
+ result += '=""';
}
return result;
}