Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSX/TSX class-name with dot #1725

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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