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

feat(css): handle css variables syntax #3239

Merged
merged 4 commits into from Jun 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,7 @@ Grammars:

- fix(csharp) add missing `catch` keyword (#3251) [Konrad Rudolph][]
- add additional keywords to csp.js (#3244) [Elijah Conners][]
- feat(css) handle css variables syntax (#3239) [Thanos Karagiannis][]
- fix(markdown) Images with empty alt or links with empty text (#3233) [Josh Goebel][]
- enh(powershell) added `pwsh` alias (#3236) [tebeco][]
- fix(r) fix bug highlighting examples in doc comments [Konrad Rudolph][]
Expand All @@ -24,6 +25,7 @@ Grammars:
[tebeco]: https://github.com/tebeco
[Pankaj Patil]: https://github.com/patil2099
[Benedikt Wilde]: https://github.com/schtandard
[Thanos Karagiannis]: https://github.com/thanoskrg


## Version 11.0.0
Expand Down
1 change: 1 addition & 0 deletions src/languages/css.js
Expand Up @@ -72,6 +72,7 @@ export default function(hljs) {
// end: /\)/,
// contains: [ hljs.CSS_NUMBER_MODE ]
// },
modes.CSS_VARIABLE,
{
className: 'attribute',
begin: '\\b(' + css.ATTRIBUTES.join('|') + ')\\b'
Expand Down
1 change: 1 addition & 0 deletions src/languages/less.js
Expand Up @@ -109,6 +109,7 @@ export default function(hljs) {
{
begin: /-(webkit|moz|ms|o)-/
},
modes.CSS_VARIABLE,
{
className: 'attribute',
begin: '\\b(' + css.ATTRIBUTES.join('|') + ')\\b',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/lib/css-shared.js
Expand Up @@ -30,6 +30,10 @@ export const MODES = (hljs) => {
'|dpi|dpcm|dppx' +
')?',
relevance: 0
},
CSS_VARIABLE: {
className: "attr",
begin: /--[A-Za-z][A-Za-z0-9_-]*/
joshgoebel marked this conversation as resolved.
Show resolved Hide resolved
}
};
};
Expand Down
1 change: 1 addition & 0 deletions src/languages/scss.js
Expand Up @@ -60,6 +60,7 @@ export default function(hljs) {
end: /\)/,
contains: [ modes.CSS_NUMBER_MODE ]
},
modes.CSS_VARIABLE,
{
className: 'attribute',
begin: '\\b(' + css.ATTRIBUTES.join('|') + ')\\b'
Expand Down
3 changes: 3 additions & 0 deletions src/languages/stylus.js
Expand Up @@ -154,6 +154,9 @@ export default function(hljs) {
]
},

// css variables
modes.CSS_VARIABLE,

// attributes
// - only from beginning of line + whitespace
// - must have whitespace after it
Expand Down
5 changes: 5 additions & 0 deletions test/markup/css/css_consistency.expect.txt
Expand Up @@ -63,3 +63,8 @@
<span class="hljs-number">50%</span> { <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">60px</span> <span class="hljs-meta">!important</span>; }
<span class="hljs-selector-tag">to</span> { <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">100px</span>; }
}

<span class="hljs-selector-tag">main</span> {
<span class="hljs-attr">--color</span>: red;
<span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--color);
}
5 changes: 5 additions & 0 deletions test/markup/css/css_consistency.txt
Expand Up @@ -63,3 +63,8 @@ a[href*="example"] {}
50% { margin-top: 60px !important; }
to { margin-top: 100px; }
}

main {
--color: red;
color: var(--color);
}
9 changes: 9 additions & 0 deletions test/markup/css/variables.expect.txt
@@ -0,0 +1,9 @@
<span class="hljs-selector-tag">body</span> {
<span class="hljs-attr">--text-color</span>: red;
<span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--text-color);
}

<span class="hljs-selector-tag">body</span> {
<span class="hljs-attr">--textBlue</span>: blue;
<span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--textBlue);
}
9 changes: 9 additions & 0 deletions test/markup/css/variables.txt
@@ -0,0 +1,9 @@
body {
--text-color: red;
color: var(--text-color);
}

body {
--textBlue: blue;
color: var(--textBlue);
}
5 changes: 5 additions & 0 deletions test/markup/less/css_consistency.expect.txt
Expand Up @@ -57,3 +57,8 @@
<span class="hljs-comment">/* src: url(&quot;/fonts/OpenSans-Regular-webfont.woff2&quot;) format(&quot;woff2&quot;),
url(&quot;/fonts/OpenSans-Regular-webfont.woff&quot;) format(&quot;woff&quot;); */</span>
}

<span class="hljs-selector-tag">main</span> {
<span class="hljs-attr">--color</span>: red;
<span class="hljs-attribute">color</span>: var(--color);
}
5 changes: 5 additions & 0 deletions test/markup/less/css_consistency.txt
Expand Up @@ -57,3 +57,8 @@ a[href*="example"] {}
/* src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
url("/fonts/OpenSans-Regular-webfont.woff") format("woff"); */
}

main {
--color: red;
color: var(--color);
}
5 changes: 5 additions & 0 deletions test/markup/scss/css_consistency.expect.txt
Expand Up @@ -57,3 +57,8 @@
<span class="hljs-comment">/* src: url(&quot;/fonts/OpenSans-Regular-webfont.woff2&quot;) format(&quot;woff2&quot;),
url(&quot;/fonts/OpenSans-Regular-webfont.woff&quot;) format(&quot;woff&quot;); */</span>
}

<span class="hljs-selector-tag">main</span> {
<span class="hljs-attr">--color</span>: red;
<span class="hljs-attribute">color</span>: var(--color);
}
5 changes: 5 additions & 0 deletions test/markup/scss/css_consistency.txt
Expand Up @@ -57,3 +57,8 @@ a[href*="example"] {}
/* src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
url("/fonts/OpenSans-Regular-webfont.woff") format("woff"); */
}

main {
--color: red;
color: var(--color);
}
5 changes: 5 additions & 0 deletions test/markup/stylus/css_consistency.expect.txt
Expand Up @@ -57,3 +57,8 @@
<span class="hljs-comment">/* src: url(&quot;/fonts/OpenSans-Regular-webfont.woff2&quot;) format(&quot;woff2&quot;),
url(&quot;/fonts/OpenSans-Regular-webfont.woff&quot;) format(&quot;woff&quot;); */</span>
}

<span class="hljs-selector-tag">main</span> {
<span class="hljs-attr">--color</span>: red;
<span class="hljs-attribute">color</span>: var(--color);
}
5 changes: 5 additions & 0 deletions test/markup/stylus/css_consistency.txt
Expand Up @@ -57,3 +57,8 @@ a[href*="example"] {}
/* src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
url("/fonts/OpenSans-Regular-webfont.woff") format("woff"); */
}

main {
--color: red;
color: var(--color);
}