Skip to content

Commit f41c5cd

Browse files
committed
JSX: Improve highlighting support. Fix #1235 and #1236
1 parent 9a542a0 commit f41c5cd

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

components/prism-jsx.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
var javascript = Prism.util.clone(Prism.languages.javascript);
44

55
Prism.languages.jsx = Prism.languages.extend('markup', javascript);
6-
Prism.languages.jsx.tag.pattern= /<\/?[\w.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+|(?:\{[^}]*\})))?|\{\.{3}\w+\}))*\s*\/?>/i;
6+
Prism.languages.jsx.tag.pattern= /<\/?[\w.:-]+\s*(?:\s+(?:[\w.:-]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+|(?:\{\{?[^}]*\}?\})))?|\{\.{3}[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\}))*\s*\/?>/i;
77

88
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">]+)/i;
99

1010
Prism.languages.insertBefore('inside', 'attr-name', {
1111
'spread': {
12-
pattern: /\{\.{3}\w+\}/,
12+
pattern: /\{\.{3}[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\}/,
1313
inside: {
14-
'punctuation': /[{}]|\.{3}/,
14+
'punctuation': /\.{3}|[{}.]/,
1515
'attr-value': /\w+/
1616
}
1717
}

components/prism-jsx.min.js

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

tests/languages/jsx/issue1235.test

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Child options={{ track: true }}>
2+
3+
----------------------------------------------------
4+
5+
[
6+
["tag", [
7+
["tag", [
8+
["punctuation", "<"],
9+
"Child"
10+
]],
11+
["attr-name", ["options"]],
12+
["script", [
13+
["punctuation", "="],
14+
["punctuation", "{"],
15+
["punctuation", "{"],
16+
" track",
17+
["punctuation", ":"],
18+
["boolean", "true"],
19+
["punctuation", "}"],
20+
["punctuation", "}"]
21+
]],
22+
["punctuation", ">"]
23+
]]
24+
]
25+
26+
----------------------------------------------------
27+
28+
Checks that attribute can contain an simple object.
29+
See #1235.

tests/languages/jsx/issue1236.test

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Child {...this.props}>
2+
3+
----------------------------------------------------
4+
5+
[
6+
["tag", [
7+
["tag", [
8+
["punctuation", "<"],
9+
"Child"
10+
]],
11+
["spread", [
12+
["punctuation", "{"],
13+
["punctuation", "..."],
14+
["attr-value", "this"],
15+
["punctuation", "."],
16+
["attr-value", "props"],
17+
["punctuation", "}"]
18+
]],
19+
["punctuation", ">"]
20+
]]
21+
]
22+
23+
----------------------------------------------------
24+
25+
Checks that spread can contain an object property.
26+
See #1236.

0 commit comments

Comments
 (0)