Files
transform/patches/htmltojsx+0.3.0.patch

78 lines
2.8 KiB
Diff

diff --git a/node_modules/htmltojsx/src/htmltojsx.js b/node_modules/htmltojsx/src/htmltojsx.js
index afe4c85..da174a2 100644
--- a/node_modules/htmltojsx/src/htmltojsx.js
+++ b/node_modules/htmltojsx/src/htmltojsx.js
@@ -268,20 +268,7 @@ function isNumeric(input) {
&& (typeof input === 'number' || parseInt(input, 10) == input);
}
-var createElement;
-if (typeof IN_BROWSER !== 'undefined' && IN_BROWSER) {
- // Browser environment, use document.createElement directly.
- createElement = function(tag) {
- return document.createElement(tag);
- };
-} else {
- // Node.js-like environment, use jsdom.
- var jsdom = require('jsdom-no-contextify').jsdom;
- var window = jsdom().defaultView;
- createElement = function(tag) {
- return window.document.createElement(tag);
- };
-}
+var createElement = function(tag) { return document.createElement(tag); };
var tempEl = createElement('div');
/**
@@ -326,19 +313,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 +328,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 +605,8 @@ HTMLtoJSX.prototype = {
result += '={' + attribute.value + '}';
} else if (attribute.value.length > 0) {
result += '="' + attribute.value.replace(/"/gm, '&quot;') + '"';
+ } else {
+ result += '=""';
}
return result;
}