Skip to content

Commit

Permalink
JSX: Allow for two levels of nesting inside JSX tags. Fix #1408
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Apr 27, 2018
1 parent a349c0c commit f1cd7c5
Show file tree
Hide file tree
Showing 3 changed files with 40 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,7 +3,7 @@
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}[a-z_$][\w$]*(?:\.[a-z_$][\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;

Expand All @@ -19,8 +19,8 @@ Prism.languages.insertBefore('inside', 'attr-name', {

Prism.languages.insertBefore('inside', 'attr-value',{
'script': {
// Allow for one level of nesting
pattern: /=(\{(?:\{[^}]*\}|[^}])+\})/i,
// Allow for two levels of nesting
pattern: /=(\{(?:\{(?:\{[^}]*\}|[^}])*\}|[^}])+\})/i,
inside: {
'script-punctuation': {
pattern: /^=(?={)/,
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.

36 changes: 36 additions & 0 deletions tests/languages/jsx/issue1408.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div style={{ marginLeft: `${sidePanelWidth}px` }}>

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

[
["tag", [
["tag", [
["punctuation", "<"],
"div"
]],
["attr-name", ["style"]],
["script", [
["script-punctuation", "="],
["punctuation", "{"],
["punctuation", "{"],
" marginLeft",
["punctuation", ":"],
["template-string", [
["string", "`"],
["interpolation", [
["interpolation-punctuation", "${"],
"sidePanelWidth",
["interpolation-punctuation", "}"]
]],
["string", "px`"]
]],
["punctuation", "}"],
["punctuation", "}"]
]],
["punctuation", ">"]
]]
]

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

Checks for template string with interpolation inside object inside JSX tag. See #1408

0 comments on commit f1cd7c5

Please sign in to comment.