Skip to content

Commit

Permalink
Merge pull request #767 from danvk/master
Browse files Browse the repository at this point in the history
Improve support for JSX
  • Loading branch information
isagalaev committed Feb 27, 2015
2 parents 94b7835 + 89339fe commit 7f38cff
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/languages/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function(hljs) {
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.REGEXP_MODE,
{ // E4X
begin: /</, end: />;/,
{ // E4X / JSX
begin: /</, end: />\s*[);\]]/,
relevance: 0,
subLanguage: 'xml'
}
Expand Down
21 changes: 21 additions & 0 deletions test/markup/javascript/jsx.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<span class="hljs-keyword">var</span> X = React.createClass({
render: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
<span class="hljs-keyword">var</span> c = <span class="hljs-keyword">this</span>.map(c =&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">Comment</span> <span class="hljs-attribute">comment</span>=<span class="hljs-value">{c}</span> <span class="hljs-attribute">key</span>=<span class="hljs-value">{c.id}</span> /&gt;</span>)</span>;
<span class="hljs-keyword">return</span> (
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">className</span>=<span class="hljs-value">'comments'</span>&gt;</span>
{c}
<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
)</span>;
},
foo: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{}
});

<span class="hljs-keyword">var</span> Comment = React.createClass({
render: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
<span class="hljs-keyword">var</span> comment = <span class="hljs-keyword">this</span>.props.comment;
<span class="hljs-keyword">return</span> (
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">li</span>&gt;</span>{comment}<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
)</span>;
}
foo: <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{}
});
21 changes: 21 additions & 0 deletions test/markup/javascript/jsx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var X = React.createClass({
render: function() {
var c = this.map(c => <Comment comment={c} key={c.id} />);
return (
<div className='comments'>
{c}
</div>
);
},
foo: function() {}
});

var Comment = React.createClass({
render: function() {
var comment = this.props.comment;
return (
<li>{comment}</li>
);
}
foo: function() {}
});
13 changes: 13 additions & 0 deletions test/markup/javascript/keywords.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">$initHighlight</span><span class="hljs-params">(block, cls)</span> </span>{
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">if</span> (cls.search(<span class="hljs-regexp">/\bno\-highlight\b/</span>) != -<span class="hljs-number">1</span>)
<span class="hljs-keyword">return</span> process(block, <span class="hljs-literal">true</span>, <span class="hljs-number">0x0F</span>) +
<span class="hljs-string">' class=""'</span>;
} <span class="hljs-keyword">catch</span> (e) {
<span class="hljs-comment">/* handle exception */</span>
}
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span> / <span class="hljs-number">2</span>; i &lt; classes.length; i++) {
<span class="hljs-keyword">if</span> (checkCondition(classes[i]) === <span class="hljs-literal">undefined</span>)
<span class="hljs-keyword">return</span> <span class="hljs-regexp">/\d+[\s/]/g</span>;
}
}
13 changes: 13 additions & 0 deletions test/markup/javascript/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function $initHighlight(block, cls) {
try {
if (cls.search(/\bno\-highlight\b/) != -1)
return process(block, true, 0x0F) +
' class=""';
} catch (e) {
/* handle exception */
}
for (var i = 0 / 2; i < classes.length; i++) {
if (checkCondition(classes[i]) === undefined)
return /\d+[\s/]/g;
}
}

0 comments on commit 7f38cff

Please sign in to comment.