mirror of
https://github.com/arsenetar/PrismHighlight.git
synced 2024-11-22 20:09:02 +00:00
37 lines
1.6 KiB
JavaScript
37 lines
1.6 KiB
JavaScript
Prism.languages.scss = Prism.languages.extend('css', {
|
|
'comment': {
|
|
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,
|
|
lookbehind: true
|
|
},
|
|
// aturle is just the @***, not the entire rule (to highlight var & stuffs)
|
|
// + add ability to highlight number & unit for media queries
|
|
'atrule': /@[\w-]+(?=\s+(\(|\{|;))/gi,
|
|
// url, compassified
|
|
'url': /([-a-z]+-)*url(?=\()/gi,
|
|
// CSS selector regex is not appropriate for Sass
|
|
// since there can be lot more things (var, @ directive, nesting..)
|
|
// a selector must start at the end of a property or after a brace (end of other rules or nesting)
|
|
// it can contain some caracters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
|
|
// the end of a selector is found when there is no rules in it ( {} or {\s}) or if there is a property (because an interpolated var
|
|
// can "pass" as a selector- e.g: proper#{$erty})
|
|
// this one was ard to do, so please be careful if you edit this one :)
|
|
'selector': /([^@;\{\}\(\)]?([^@;\{\}\(\)]|&|\#\{\$[-_\w]+\})+)(?=\s*\{(\}|\s|[^\}]+(:|\{)[^\}]+))/gm
|
|
});
|
|
|
|
Prism.languages.insertBefore('scss', 'atrule', {
|
|
'keyword': /@(if|else if|else|for|each|while|import|extend|debug|warn|mixin|include|function|return)|(?=@for\s+\$[-_\w]+\s)+from/i
|
|
});
|
|
|
|
Prism.languages.insertBefore('scss', 'property', {
|
|
// var and interpolated vars
|
|
'variable': /((\$[-_\w]+)|(#\{\$[-_\w]+\}))/i
|
|
});
|
|
|
|
Prism.languages.insertBefore('scss', 'ignore', {
|
|
'placeholder': /%[-_\w]+/i,
|
|
'statement': /\B!(default|optional)\b/gi,
|
|
'boolean': /\b(true|false)\b/g,
|
|
'null': /\b(null)\b/g,
|
|
'operator': /\s+([-+]{1,2}|={1,2}|!=|\|?\||\?|\*|\/|\%)\s+/g
|
|
});
|