Skip to content

Commit

Permalink
React component tags are styled as classes in JSX (#1519)
Browse files Browse the repository at this point in the history
The PR adds a class-name alias to all the tags of React components. Tags which start
with an uppercase letter are considered React components. HTML tags remain unchanged.

Fixes #1518.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Aug 20, 2018
1 parent c40f604 commit 3e1a9a3
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions components/prism-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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.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.

4 changes: 2 additions & 2 deletions tests/languages/jsx/issue1235.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"Child"
["class-name", "Child"]
]],
["attr-name", ["options"]],
["script", [
Expand All @@ -26,4 +26,4 @@
----------------------------------------------------

Checks that attribute can contain an simple object.
See #1235.
See #1235.
4 changes: 2 additions & 2 deletions tests/languages/jsx/issue1236.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"Child"
["class-name", "Child"]
]],
["spread", [
["punctuation", "{"],
Expand All @@ -23,4 +23,4 @@
----------------------------------------------------

Checks that spread can contain an object property.
See #1236.
See #1236.
10 changes: 5 additions & 5 deletions tests/languages/jsx/issue1335.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"Button"
["class-name", "Button"]
]],
["attr-name", ["onClick"]],
["script", [
Expand All @@ -41,7 +41,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"Component"
["class-name", "Component"]
]],
["attr-name", ["data"]],
["script", [
Expand Down Expand Up @@ -76,7 +76,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"Component"
["class-name", "Component"]
]],
["attr-name", ["title"]],
["script", [
Expand All @@ -98,7 +98,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"Component"
["class-name", "Component"]
]],
["attr-name", ["title"]],
["script", [
Expand All @@ -121,4 +121,4 @@

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

Handles nested pairs of curly braces inside tag attribute. See #1335
Handles nested pairs of curly braces inside tag attribute. See #1335
6 changes: 3 additions & 3 deletions tests/languages/jsx/issue1342.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"CodeView"
["class-name", "CodeView"]
]],
["attr-name", ["title"]],
["script", [
Expand Down Expand Up @@ -42,12 +42,12 @@
["tag", [
["tag", [
["punctuation", "</"],
"CodeView"
["class-name", "CodeView"]
]],
["punctuation", ">"]
]]
]

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

Checks for nested tag with JSX inside another tag with JSX. See #1342
Checks for nested tag with JSX inside another tag with JSX. See #1342
4 changes: 2 additions & 2 deletions tests/languages/jsx/issue1364.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
["tag", [
["tag", [
["punctuation", "<"],
"CodeView"
["class-name", "CodeView"]
]],
["attr-name", ["title"]],
["script", [
Expand All @@ -22,4 +22,4 @@

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

Checks for empty objects in JSX. See #1364
Checks for empty objects in JSX. See #1364
4 changes: 2 additions & 2 deletions tests/languages/jsx/tag_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var myElement = <MyComponent someProperty={true} />;
["tag", [
["tag", [
["punctuation", "<"],
"MyComponent"
["class-name", "MyComponent"]
]],
["attr-name", ["someProperty"]],
["script", [
Expand Down Expand Up @@ -80,4 +80,4 @@ var myElement = <MyComponent someProperty={true} />;

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

Checks for JSX tags.
Checks for JSX tags.
4 changes: 2 additions & 2 deletions tests/languages/tsx/tag_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Test extends Component {
["tag", [
["tag", [
["punctuation", "<"],
"MyComponent"
["class-name", "MyComponent"]
]],
["attr-name", ["someProperty"]],
["script", [
Expand Down Expand Up @@ -102,4 +102,4 @@ class Test extends Component {

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

Checks for TSX tags.
Checks for TSX tags.

0 comments on commit 3e1a9a3

Please sign in to comment.