Skip to content

Commit

Permalink
JSX: Fix highlighting of attributes containing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Mar 2, 2017
1 parent 0a3d2a9 commit 867ea42
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/prism-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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\.:-]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+|(\{[\w\W]*?\})))?|\{\.{3}\w+\})\s*)*\/?>/i;

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

Prism.languages.insertBefore('inside', 'attr-name', {
'spread': {
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/issue1103.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var myDivElement = <div foo="bar baz" />;

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

[
["keyword", "var"],
" myDivElement ",
["operator", "="],
["tag", [
["tag", [
["punctuation", "<"],
"div"
]],
["attr-name", ["foo"]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"bar baz",
["punctuation", "\""]
]],
["punctuation", "/>"]
]],
["punctuation", ";"]
]

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

Checks that quoted attribute values can contain spaces.
See #1103.

0 comments on commit 867ea42

Please sign in to comment.