From e96b5c9ba0ba812905ccd257699061af3802edfa Mon Sep 17 00:00:00 2001 From: Solar Olugebefola Date: Wed, 3 Feb 2016 17:02:23 -0500 Subject: [PATCH 1/4] Handle braces in text. --- src/htmltojsx.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/htmltojsx.js b/src/htmltojsx.js index d420006..00bbec3 100644 --- a/src/htmltojsx.js +++ b/src/htmltojsx.js @@ -446,6 +446,12 @@ HTMLtoJSX.prototype = { return '{' + JSON.stringify(whitespace) + '}'; }); } else { + // Handle any curly braces. + text = text + .replace(/\'/g, "\"") + .replace(/(\{|\})/g, function(brace) { + return '{\'' + brace + '\'}'; + }); // If there's a newline in the text, adjust the indent level if (text.indexOf('\n') > -1) { text = text.replace(/\n\s*/g, this._getIndentedNewline()); From 4b621c17296ff41e88e63ce76c0e15936317240e Mon Sep 17 00:00:00 2001 From: Solar Olugebefola Date: Wed, 3 Feb 2016 17:07:39 -0500 Subject: [PATCH 2/4] Adjustment. --- src/htmltojsx.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/htmltojsx.js b/src/htmltojsx.js index 00bbec3..fc91c7a 100644 --- a/src/htmltojsx.js +++ b/src/htmltojsx.js @@ -434,7 +434,7 @@ HTMLtoJSX.prototype = { return; } - var text = escapeSpecialChars(node.textContent) + var text = escapeSpecialChars(node.textContent); if (this._inPreTag) { // If this text is contained within a
, we need to ensure the JSX
@@ -448,7 +448,6 @@ HTMLtoJSX.prototype = {
     } else {
       // Handle any curly braces.
       text = text
-        .replace(/\'/g, "\"")
         .replace(/(\{|\})/g, function(brace) {
             return '{\'' + brace + '\'}';
         });

From f68247a3b9af32a799a8c6895e2f0932662e478a Mon Sep 17 00:00:00 2001
From: Solar Olugebefola 
Date: Mon, 8 Feb 2016 23:49:19 -0500
Subject: [PATCH 3/4] Add arguments to cli

Allow for conversion to `module.exports` rather than `React.createClass` using option `e`.  Or no wrapper at all with option `g`
---
 src/cli.js | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/cli.js b/src/cli.js
index 9e72cbe..d4480b1 100755
--- a/src/cli.js
+++ b/src/cli.js
@@ -13,6 +13,10 @@ function getArgs() {
     )
     .describe('className', 'Create a React component (wraps JSX in React.createClass call)')
     .alias('className', 'c')
+    .boolean('e')
+    .describe('e', 'Decide whether to wrap in module.exports')
+    .boolean('g')
+    .describe('g', 'Decide whether to format for grouping with other jsx files(i.e. no wrapper)')
     .help('help')
     .example(
       '$0 -c AwesomeComponent awesome.htm',
@@ -38,7 +42,9 @@ function main() {
     }
     var converter = new HTMLtoJSX({
       createClass: !!argv.className,
-      outputClassName: argv.className
+      outputClassName: argv.className,
+      exports: argv.e && !argv.g,
+      group: argv.g && !argv.e
     });
     var output = converter.convert(input);
     console.log(output);

From bfb243b3d14f2d6d389df2a18b02baf57e14934c Mon Sep 17 00:00:00 2001
From: Solar Olugebefola 
Date: Mon, 8 Feb 2016 23:54:04 -0500
Subject: [PATCH 4/4] Allow `e` and `g` options

`e` for `module.exports` wrapper and `g` for no wrapper, when grouping files.
---
 src/htmltojsx.js | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/htmltojsx.js b/src/htmltojsx.js
index fc91c7a..57de980 100644
--- a/src/htmltojsx.js
+++ b/src/htmltojsx.js
@@ -198,14 +198,19 @@ HTMLtoJSX.prototype = {
     var containerEl = createElement('div');
     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';
+    if (this.config.exports) {
+       this.output = 'module.exports = ';
+    } else if (this.config.group){
+    } else {
+      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';
       }
-      this.output += this.config.indent + 'render: function() {' + "\n";
-      this.output += this.config.indent + this.config.indent + 'return (\n';
     }
 
     if (this._onlyOneTopLevel(containerEl)) {
@@ -224,7 +229,7 @@ HTMLtoJSX.prototype = {
       this.output += this.config.indent + this.config.indent + ');\n';
       this.output += this.config.indent + '}\n';
       this.output += '});';
-    }
+    }else if (this.config.exports){ this.output += ';';}
     return this.output;
   },