Skip to content

Commit

Permalink
JSX: Made $ a valid character for attribute names (#2144)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceymard authored and RunDevelopment committed Jan 5, 2020
1 parent 694a81b commit f018cf0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/prism-jsx.js
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['tag'].pattern = /^<\/?[^\s>\/]*/i;
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">]+)/i;
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.

25 changes: 25 additions & 0 deletions tests/languages/jsx/dollars-in-attrs.test
@@ -0,0 +1,25 @@
<div $$="bar baz" />;

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

[
["tag", [
["tag", [
["punctuation", "<"],
"div"
]],
["attr-name", ["$$"]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"bar baz",
["punctuation", "\""]
]],
["punctuation", "/>"]
]],
["punctuation", ";"]
]

----------------------------------------------------
Checks that attribute names can contain $
No issue filed

0 comments on commit f018cf0

Please sign in to comment.