-
Notifications
You must be signed in to change notification settings - Fork 46k
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
Escaping <style> tag content #3496
Comments
Unless I'm mistaken you must use |
@syranide 👍 As noted it works when using |
Maybe using // Just define a simple `<div>` element here. Everything works just fine.
var myDiv = <div>test</div>;
// As everything between two { ... } brackets is interpreted as plain JS, the following
// style definition will have the variable `myDiv` as contnat.
var myStyle = <style>.className { myDiv }</style>
// The following will not parse as `2px` is not valid JavaScript.
var myStyleAgain = <style>.className { padding: 2px }</style> You can look at the output of the babel-online-repl here: http://bit.ly/19heJyO The main issue is that in JSX everything between Hope this is helpful. |
@jviereck Interesting... Personally I'm not handwriting the css inside the styletag. I'm using a browserify transform (post babelify) to require the styling -> css-string. So I'm not getting any of the babel errors. But that's beside the point. I guess the issue is whether jsx should support the style tag or not...? If it is supported I think it makes sense to support css inside it? Or...? What do you guys think? My two cents;
|
I thikn if would be nice if we could use shorthand to report jsxTrans. if we want to set inner content w/o escaping. May be something like: var a = <div !>url("yolo.png")<div>; Yes, it's danger, but can you imagin if all templates engines force us to use long syntax construction for unescaped content. We have this features in other template engines and i think it is not necessarily to use React only fo complex components with some logic, but a plain template engine! I have no Mustache or Embeddedjs (etc.) in my project cause of React and it's cool and i believe that's some features would be easy accessible. |
JSX is very much a simple transform and we have no intention of making it special case specific tags. We also don't want to introduce complicated semantics. In this case you should use |
According to #3399 and #3465 React uses
escapeTextContentForBrowser
to replace " with"
etc. This behavior is sane and awesome!Problem is that it also happens inside
<style>
tags, which is not so great. Turns things likeurl("yolo.png")
intourl("yolo.png")
which of course breaks.It works fine if applied using
dangerouslySetInnerHTML
.The text was updated successfully, but these errors were encountered: