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

React JSX support? #494

Closed
gre opened this issue Jun 23, 2014 · 13 comments
Closed

React JSX support? #494

gre opened this issue Jun 23, 2014 · 13 comments

Comments

@gre
Copy link

gre commented Jun 23, 2014

Hi,

Is there any way to highlight (and detect) JavaScript code using the React JSX syntax? It would be awesome.

Best regards,
gre

@gre
Copy link
Author

gre commented Jun 23, 2014

Oh, actually it seems to be pretty enough with the current hljs, I'm sorry to haven't test properly before.

Thanks

@gre gre closed this as completed Jun 23, 2014
@isagalaev
Copy link
Member

I have no idea what React JSX even is but I'm glad you've found highlight.js works for you :-)

@dmptrluke
Copy link

Apparently some bizarre xml-like syntax thing for javascript, made by
facebook! http://facebook.github.io/react/docs/jsx-in-depth.html

On Tue, Jun 24, 2014 at 11:09 AM, Ivan Sagalaev notifications@github.com
wrote:

I have no idea what React JSX even is but I'm glad you've found
highlight.js works for you :-)


Reply to this email directly or view it on GitHub
#494 (comment)
.

@isagalaev
Copy link
Member

It looks pretty much like E4X — a JavaScript extension for embedded literal XML. Highlight.js supports that and I suppose JSX is basically the same idea under a different name.

@rstacruz
Copy link

The problem with E4X (and hence, JSX) support in hl.js is that in requires your tag to end in >;:

https://github.com/isagalaev/highlight.js/pull/123/files#diff-223ea81c103e681d4def42a5047c8becR34

var compo = React.render(<Component />, mountnode); /* not ok */

/* ok */
render: function () {
  return <div>Hello {this.props.name}</div>;
}

@jbe456
Copy link

jbe456 commented Jan 6, 2016

I still have the issue with the latest version:

jsx

You can see from the screenshot and the HTML below that the XML span incorrectly covers the rest of the code.

<code class="hljs javascript"><span class="hljs-keyword">var</span> HelloWorld = React.createClass({
  render: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span>
        Hello, <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"text"</span> <span class="hljs-attribute">placeholder</span>=<span class="hljs-value">"Your name here"</span> /&gt;</span>!
        It is {this.props.date.toTimeString()}
      <span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span>
    );
  }
});

setInterval(function() {
  ReactDOM.render(
    <span class="hljs-tag">&lt;<span class="hljs-title">HelloWorld</span> <span class="hljs-attribute">date</span>=<span class="hljs-value">{new</span> <span class="hljs-attribute">Date</span>()} /&gt;</span>,
    document.getElementById('example')
  );
}, 500);</span></code>

Any plan on fixing it?

@isagalaev
Copy link
Member

@jbe456 yeah, it wasn't fixed. We have a separate issue on that — #839. It turned out to be a real inconvenience for our current parser.

@MartinHaeusler
Copy link

+1, Typescript (*.tsx) Support would be even better.

@namestise
Copy link

Why this issue being closed? JSX is rendered very ugly
screen shot 2017-03-15 at 3 26 03 pm

@axhamre
Copy link

axhamre commented Dec 22, 2018

Any updates on this?

@egor-rogov
Copy link
Collaborator

Does anyone have an idea how to fix it? Pull requests are welcome.

@bexuma
Copy link

bexuma commented Jan 27, 2019

@egor-rogov, consider switching to Prism.js, they do support jsx language highlighting.

@yourWaifu
Copy link

I found this thread on a Google search, but you should go here instead: #2998

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

No branches or pull requests