Skip to content

Commit

Permalink
Sass: Fix comments, operators and selectors and simplified patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Aug 30, 2015
1 parent 35b8c50 commit 28759d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions components/prism-sass.js
@@ -1,7 +1,10 @@
(function(Prism) {
Prism.languages.sass = Prism.languages.extend('css', {
// Sass comments don't need to be closed, only indented
'comment': /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t]+.+)*/m
'comment': {
pattern: /^([ \t]*)\/[\/*].*(?:(?:\r?\n|\r)\1[ \t]+.+)*/m,
lookbehind: true
}
});

Prism.languages.insertBefore('sass', 'atrule', {
Expand All @@ -10,21 +13,20 @@
// Includes support for = and + shortcuts
pattern: /^(?:[ \t]*)[@+=].+/m,
inside: {
'atrule': /^(?:[ \t]*)(?:@[\w-]+|[+=])/m
'atrule': /(?:@[\w-]+|[+=])/m
}
}
});
delete Prism.languages.sass.atrule;


var variable = /((\$[-_\w]+)|(#\{\$[-_\w]+\}))/i;
var operator = /[-+]{1,2}|==?|!=|\|?\||\?|\*|\/|%/;
var operator = /[-+*\/%]|[=!]=|<=?|>=?|\b(?:and|or|not)\b/;

Prism.languages.insertBefore('sass', 'property', {
// We want to consume the whole line
'variable-line': {
pattern: /(^|(?:\r?\n|\r))[ \t]*\$.+/,
lookbehind: true,
pattern: /^[ \t]*\$.+/m,
inside: {
'punctuation': /:/,
'variable': variable,
Expand All @@ -33,8 +35,7 @@
},
// We want to consume the whole line
'property-line': {
pattern: /(^|(?:\r?\n|\r))[ \t]*(?:[^:\s]+[ ]*:.*|:[^:\s]+.*)/i,
lookbehind: true,
pattern: /^[ \t]*(?:[^:\s]+ *:.*|:[^:\s]+.*)/m,
inside: {
'property': [
/[^:\s]+(?=\s*:)/,
Expand All @@ -58,7 +59,7 @@
delete Prism.languages.sass.selector;
Prism.languages.insertBefore('sass', 'punctuation', {
'selector': {
pattern: /([ \t]*).+(?:,(?:\r?\n|\r)\1[ \t]+.+)*/,
pattern: /([ \t]*)\S(?:,?[^,\r\n]+)*(?:,(?:\r?\n|\r)\1[ \t]+\S(?:,?[^,\r\n]+)*)*/,
lookbehind: true
}
});
Expand Down
2 changes: 1 addition & 1 deletion components/prism-sass.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 28759d0

Please sign in to comment.