Skip to content

Commit fbe82b8

Browse files
fyrkantGolmote
authored andcommitted
added tsx support (#1280)
* added tsx support * fixed order in components.js and added tsx example file * escape less than and capitalize tsx
1 parent 5de1b1f commit fbe82b8

File tree

9 files changed

+151
-4
lines changed

9 files changed

+151
-4
lines changed

components.js

+4
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ var components = {
506506
"require": ["markup", "javascript"],
507507
"owner": "vkbansal"
508508
},
509+
"tsx": {
510+
"title": "React TSX",
511+
"require": ["jsx", "typescript"]
512+
},
509513
"renpy": {
510514
"title": "Ren'py",
511515
"owner": "HyuchiaDiego"

components/prism-tsx.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var typescript = Prism.util.clone(Prism.languages.typescript);
2+
Prism.languages.tsx = Prism.languages.extend('jsx', typescript);

components/prism-tsx.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-tsx.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h1>React TSX</h1>
2+
<p>To use this language, use the class "language-tsx".</p>
3+
4+
<h2>Full example</h2>
5+
<pre><code>import * as React from 'react';
6+
7+
interface IState {
8+
clicks: number;
9+
}
10+
11+
export class Clicker extends React.Component&lt;any, IState> {
12+
constructor(props) {
13+
super(props);
14+
15+
this.state = {
16+
clicks: 0,
17+
};
18+
}
19+
20+
public clickHandler = () => {
21+
this.setState({ clicks: this.state.clicks + 1 });
22+
}
23+
24+
public render() {
25+
return (
26+
&lt;div>
27+
&lt;p>You have clicked the button {this.state.clicks} time(s).&lt;/p>
28+
&lt;p>
29+
&lt;button onClick={this.clickHandler}>click me&lt;/button>
30+
&lt;/p>
31+
&lt;/div>
32+
);
33+
}
34+
}</code></pre>

plugins/autoloader/prism-autoloader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
}
55

66
// The dependencies map is built automatically with gulp
7-
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","fsharp":"clike","flow":"javascript","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","vbnet":"basic","wiki":"markup","xeora":"markup"}/*]*/;
7+
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","fsharp":"clike","flow":"javascript","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","tsx":["jsx","typescript"],"twig":"markup","typescript":"javascript","vbnet":"basic","wiki":"markup","xeora":"markup"}/*]*/;
88

99
var lang_data = {};
1010

plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
1111
}
1212

1313
// The languages map is built automatically with gulp
14-
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
14+
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","tsx":"React Tsx","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
1515
Prism.plugins.toolbar.registerButton('show-language', function(env) {
1616
var pre = env.element.parentNode;
1717
if (!pre || !/pre/i.test(pre.nodeName)) {

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/tsx/tag_feature.test

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
var myDivElement = <div className="foo" />;
2+
var myElement = <MyComponent someProperty={true} />;
3+
<div {...foo}>
4+
class Test extends Component {
5+
render() {
6+
return <p onClick={this.clickHandler}>Hello world.</p>;
7+
}
8+
}
9+
10+
----------------------------------------------------
11+
12+
[
13+
["keyword", "var"],
14+
" myDivElement ",
15+
["operator", "="],
16+
["tag", [
17+
["tag", [
18+
["punctuation", "<"],
19+
"div"
20+
]],
21+
["attr-name", ["className"]],
22+
["attr-value", [
23+
["punctuation", "="],
24+
["punctuation", "\""],
25+
"foo",
26+
["punctuation", "\""]
27+
]],
28+
["punctuation", "/>"]
29+
]],
30+
["punctuation", ";"],
31+
32+
["keyword", "var"],
33+
" myElement ",
34+
["operator", "="],
35+
["tag", [
36+
["tag", [
37+
["punctuation", "<"],
38+
"MyComponent"
39+
]],
40+
["attr-name", ["someProperty"]],
41+
["script", [
42+
["punctuation", "="],
43+
["punctuation", "{"],
44+
["boolean", "true"],
45+
["punctuation", "}"]
46+
]],
47+
["punctuation", "/>"]
48+
]],
49+
["punctuation", ";"],
50+
["tag", [
51+
["tag", [
52+
["punctuation", "<"],
53+
"div"
54+
]],
55+
["spread", [
56+
["punctuation", "{"],
57+
["punctuation", "..."],
58+
["attr-value", "foo"],
59+
["punctuation", "}"]
60+
]],
61+
["punctuation", ">"]
62+
]],
63+
64+
["keyword", "class"],
65+
["class-name", ["Test"]],
66+
["keyword", "extends"],
67+
["class-name", ["Component"]],
68+
["punctuation", "{"],
69+
["function", "render"],
70+
["punctuation", "("],
71+
["punctuation", ")"],
72+
["punctuation", "{"],
73+
["keyword","return"],
74+
["tag", [
75+
["tag", [
76+
["punctuation", "<"],
77+
"p"
78+
]],
79+
["attr-name", ["onClick"]],
80+
["script", [
81+
["punctuation", "="],
82+
["punctuation", "{"],
83+
["keyword", "this"],
84+
["punctuation", "."],
85+
"clickHandler",
86+
["punctuation", "}"]
87+
]],
88+
["punctuation", ">"]
89+
]],
90+
"Hello world",
91+
["punctuation", "."],
92+
["tag", [
93+
["tag", [
94+
["punctuation", "</"],
95+
"p"
96+
]],
97+
["punctuation", ">"]
98+
]],
99+
["punctuation", ";"],
100+
["punctuation", "}"],
101+
["punctuation","}"]
102+
]
103+
104+
----------------------------------------------------
105+
106+
Checks for TSX tags.

0 commit comments

Comments
 (0)