Skip to content

Commit

Permalink
JSX: Improve highlighting support. Fix #1235 and #1236
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Nov 29, 2017
1 parent 9a542a0 commit f41c5cd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
6 changes: 3 additions & 3 deletions components/prism-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
var javascript = Prism.util.clone(Prism.languages.javascript);

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

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

Prism.languages.insertBefore('inside', 'attr-name', {
'spread': {
pattern: /\{\.{3}\w+\}/,
pattern: /\{\.{3}[a-z_$][\w$]*(?:\.[a-z_$][\w$]*)*\}/,
inside: {
'punctuation': /[{}]|\.{3}/,
'punctuation': /\.{3}|[{}.]/,
'attr-value': /\w+/
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-jsx.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions tests/languages/jsx/issue1235.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Child options={{ track: true }}>

----------------------------------------------------

[
["tag", [
["tag", [
["punctuation", "<"],
"Child"
]],
["attr-name", ["options"]],
["script", [
["punctuation", "="],
["punctuation", "{"],
["punctuation", "{"],
" track",
["punctuation", ":"],
["boolean", "true"],
["punctuation", "}"],
["punctuation", "}"]
]],
["punctuation", ">"]
]]
]

----------------------------------------------------

Checks that attribute can contain an simple object.
See #1235.
26 changes: 26 additions & 0 deletions tests/languages/jsx/issue1236.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Child {...this.props}>

----------------------------------------------------

[
["tag", [
["tag", [
["punctuation", "<"],
"Child"
]],
["spread", [
["punctuation", "{"],
["punctuation", "..."],
["attr-value", "this"],
["punctuation", "."],
["attr-value", "props"],
["punctuation", "}"]
]],
["punctuation", ">"]
]]
]

----------------------------------------------------

Checks that spread can contain an object property.
See #1236.

0 comments on commit f41c5cd

Please sign in to comment.