Skip to content

Commit

Permalink
SCSS: Highlight variables inside selectors and properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Jul 7, 2016
1 parent fd09391 commit d6b5c2f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
12 changes: 10 additions & 2 deletions components/prism-scss.js
Expand Up @@ -23,7 +23,8 @@ Prism.languages.scss = Prism.languages.extend('css', {
// Initial look-ahead is used to prevent matching of blank selectors
pattern: /(?=\S)[^@;\{\}\(\)]?([^@;\{\}\(\)]|&|#\{\$[-_\w]+\})+(?=\s*\{(\}|\s|[^\}]+(:|\{)[^\}]+))/m,
inside: {
'placeholder': /%[-_\w]+/
'placeholder': /%[-_\w]+/,
'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
}
}
});
Expand All @@ -38,7 +39,14 @@ Prism.languages.insertBefore('scss', 'atrule', {
]
});

Prism.languages.insertBefore('scss', 'property', {
Prism.languages.scss.property = {
pattern: /(?:[\w-]|\$[-_\w]+|#\{\$[-_\w]+\})+(?=\s*:)/i,
inside: {
'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
}
};

Prism.languages.insertBefore('scss', 'important', {
// var and interpolated vars
'variable': /\$[-_\w]+|#\{\$[-_\w]+\}/
});
Expand Down
2 changes: 1 addition & 1 deletion components/prism-scss.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/scss+haml/scss_inclusion.test
Expand Up @@ -16,7 +16,7 @@
["filter-name", ":scss"],
["selector", ["#main "]],
["punctuation", "{"],
["property", "width"],
["property", ["width"]],
["punctuation", ":"],
["variable", "$width"],
["punctuation", ";"],
Expand All @@ -27,7 +27,7 @@
["filter-name", ":scss"],
["selector", ["#main "]],
["punctuation", "{"],
["property", "width"],
["property", ["width"]],
["punctuation", ":"],
["variable", "$width"],
["punctuation", ";"],
Expand Down
2 changes: 1 addition & 1 deletion tests/languages/scss/atrule_feature.test
Expand Up @@ -6,7 +6,7 @@
["atrule", [
["rule", "@media"],
["punctuation", "("],
["property", "min-width"],
["property", ["min-width"]],
["punctuation", ":"],
" 600px",
["punctuation", ")"]
Expand Down
23 changes: 23 additions & 0 deletions tests/languages/scss/property_feature.test
@@ -0,0 +1,23 @@
$bg: background;
$color: color;
div {
$bg: none;
background-#{$color}: blue;
#{$bg}-repeat: no-repeat;
}

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

[
["property", [["variable", "$bg"]]], ["punctuation", ":"], " background", ["punctuation", ";"],
["property", [["variable", "$color"]]], ["punctuation", ":"], " color", ["punctuation", ";"],
["selector", ["div "]], ["punctuation", "{"],
["property", [["variable", "$bg"]]], ["punctuation", ":"], " none", ["punctuation", ";"],
["property", ["background-", ["variable", "#{$color}"]]], ["punctuation", ":"], " blue", ["punctuation", ";"],
["property", [["variable", "#{$bg}"], "-repeat"]], ["punctuation", ":"], " no-repeat", ["punctuation", ";"],
["punctuation", "}"]
]

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

Checks for properties.
2 changes: 1 addition & 1 deletion tests/languages/scss/selector_feature.test
Expand Up @@ -15,7 +15,7 @@ p, div {}
["selector", ["&:hover "]], ["punctuation", "{"], ["punctuation", "}"],
["selector", ["&-sidebar "]], ["punctuation", "{"], ["punctuation", "}"],
["selector", ["#context a", ["placeholder", "%extreme"]]], ["punctuation", "{"], ["punctuation", "}"],
["selector", ["#{$selector}:before "]], ["punctuation", "{"], ["punctuation", "}"]
["selector", [["variable", "#{$selector}"], ":before "]], ["punctuation", "{"], ["punctuation", "}"]
]

----------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/languages/scss/statement_feature.test
Expand Up @@ -4,7 +4,7 @@ $foo: "bar" !default;
----------------------------------------------------

[
["variable", "$foo"],
["property", [["variable", "$foo"]]],
["punctuation", ":"],
["string", "\"bar\""],
["statement", "!default"],
Expand Down

0 comments on commit d6b5c2f

Please sign in to comment.