Skip to content
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

Handle inline <style>s #35

Closed
karlfloersch opened this issue Sep 16, 2015 · 8 comments
Closed

Handle inline <style>s #35

karlfloersch opened this issue Sep 16, 2015 · 8 comments
Labels

Comments

@karlfloersch
Copy link

I've been playing around with react-magic, testing it on a number of different websites. I got one syntax error quite often. I've included a few examples of this error.

How to reproduce For each site I opened up the debug console (in Firefox), and ran this command (taken from the bookmarklet):

    (function(b){function c(){if(0!==d.length){var e=d.shift(),a=b.createElement("script");a.src=e;a.onload=c;b.body.appendChild(a)}}var d=["http://fb.me/react-0.13.3.min.js","http://fb.me/JSXTransformer-0.13.3.js","http://reactjs.github.io/react-magic/magic.min.js"];c();return!1})(document);
URL React-Magic Error
http://www.uschs.org/ Error: Something bad happened when transforming HTML to JSX: Error: Parse Error: Line 268: Unexpected token :
http://www.starwars.com/news Error: Something bad happened when transforming HTML to JSX: Error: Parse Error: Line 5: Unexpected token :
http://karl.tech/ Error: Something bad happened when transforming HTML to JSX: Error: Parse Error: Line 12: Unexpected token :

Maybe it has to do with inline styles?

@Daniel15
Copy link
Member

Inline styles should be fine... I'll try to look into this soon and determine what the problem is.

@sicks
Copy link
Contributor

sicks commented Sep 16, 2015

Cause looks to be internal stylesheets. Inline styles are being handled correctly the 'JSX way' but internal stylesheets are not.

<style>
  h1 { color: red; }
</style>

needs to convert to

<style>{"\
  h1 { color: red; }\
"}</style>

(thanks stackoverflow!)

@Daniel15
Copy link
Member

Thanks! Sounds like we need custom handling. That can be done :)

(as an aside, using \ to escape newlines doesn't have very good browser support, so it's not really recommended)

@Daniel15 Daniel15 changed the title Something bad happened when transforming HTML to JSX. Parse Error: Unexpected token : Handle inline <style>s Sep 16, 2015
@Daniel15 Daniel15 added the bug label Sep 16, 2015
@sicks
Copy link
Contributor

sicks commented Sep 16, 2015

We didn't need those newlines anyway!

@sicks
Copy link
Contributor

sicks commented Sep 17, 2015

So #36 fixes internal stylesheets, but the battle against curly braces is still far from over. It's easily handled in <style> tags as we can expect CSS to contain curly braces, but I'm not sure how to best address unpredictable ones. For example, in that star wars page there's an iframe with a name attribute that contains { } which again breaks the JSX parser.

@ssorallen
Copy link
Contributor

@Daniel15, can you release a new version on NPM with this fix?

@Daniel15
Copy link
Member

@ssorallen Pushed to NPM as 0.2.5 👍

@ssorallen
Copy link
Contributor

@Daniel15 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants