Skip to content

Commit

Permalink
Support JSX/TSX class-name with dot (#1725)
Browse files Browse the repository at this point in the history
Adds class-name highlighting for JSX/TSX tag names containing dots.
  • Loading branch information
RexSkz authored and RunDevelopment committed Feb 12, 2019
1 parent 5311ca3 commit 4362e42
Show file tree
Hide file tree
Showing 4 changed files with 47 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 @@ -7,7 +7,7 @@ Prism.languages.jsx.tag.pattern= /<\/?(?:[\w.:-]+\s*(?:\s+(?:[\w.:-]+(?:=(?:("|'

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

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.

22 changes: 22 additions & 0 deletions tests/languages/jsx/tag_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var myDivElement = <div className="foo" />;
var myElement = <MyComponent someProperty={true} />;
<div {...foo}></div>
<> </>
<Tree.TreeNode.Item leaf={true}></Tree.TreeNode.Item>

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

Expand Down Expand Up @@ -75,6 +76,27 @@ var myElement = <MyComponent someProperty={true} />;
["punctuation", "</"]
]],
["punctuation", ">"]
]],
["tag", [
["tag", [
["punctuation", "<"],
["class-name", "Tree.TreeNode.Item"]
]],
["attr-name", ["leaf"]],
["script", [
["script-punctuation", "="],
["punctuation", "{"],
["boolean", "true"],
["punctuation", "}"]
]],
["punctuation", ">"]
]],
["tag", [
["tag", [
["punctuation", "</"],
["class-name", "Tree.TreeNode.Item"]
]],
["punctuation", ">"]
]]
]

Expand Down
23 changes: 23 additions & 0 deletions tests/languages/tsx/tag_feature.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var myDivElement = <div className="foo" />;
var myElement = <MyComponent someProperty={true} />;
<div {...foo} />
<Tree.TreeNode.Item leaf={true}></Tree.TreeNode.Item>
class Test extends Component {
render() {
return <p onClick={this.clickHandler}>Hello world.</p>;
Expand Down Expand Up @@ -61,6 +62,28 @@ class Test extends Component {
["punctuation", "/>"]
]],

["tag", [
["tag", [
["punctuation", "<"],
["class-name", "Tree.TreeNode.Item"]
]],
["attr-name", ["leaf"]],
["script", [
["script-punctuation", "="],
["punctuation", "{"],
["boolean", "true"],
["punctuation", "}"]
]],
["punctuation", ">"]
]],
["tag", [
["tag", [
["punctuation", "</"],
["class-name", "Tree.TreeNode.Item"]
]],
["punctuation", ">"]
]],

["keyword", "class"],
["class-name", ["Test"]],
["keyword", "extends"],
Expand Down

0 comments on commit 4362e42

Please sign in to comment.