Merge pull request #233 from probonogeek/master
CSS Sytnax Rule Improvements
This commit is contained in:
commit
40d449ffb4
1 changed files with 119 additions and 19 deletions
|
|
@ -122,12 +122,12 @@ var CssHighlightRules = function() {
|
||||||
return re.join("");
|
return re.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$rules = {
|
var base_ruleset = [
|
||||||
"start" : [ {
|
{
|
||||||
token : "comment", // multi line comment
|
token : "comment", // multi line comment
|
||||||
regex : "\\/\\*",
|
regex : "\\/\\*",
|
||||||
next : "comment"
|
next : "ruleset_comment"
|
||||||
}, {
|
},{
|
||||||
token : "string", // single line
|
token : "string", // single line
|
||||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -190,12 +190,6 @@ var CssHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token : "constant.numeric", // hex3 color
|
token : "constant.numeric", // hex3 color
|
||||||
regex : "#[a-fA-F0-9]{3}"
|
regex : "#[a-fA-F0-9]{3}"
|
||||||
}, {
|
|
||||||
token : "lparen",
|
|
||||||
regex : "\{"
|
|
||||||
}, {
|
|
||||||
token : "rparen",
|
|
||||||
regex : "\}"
|
|
||||||
}, {
|
}, {
|
||||||
token : function(value) {
|
token : function(value) {
|
||||||
if (properties.hasOwnProperty(value.toLowerCase())) {
|
if (properties.hasOwnProperty(value.toLowerCase())) {
|
||||||
|
|
@ -215,15 +209,121 @@ var CssHighlightRules = function() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
|
regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
|
||||||
}],
|
}
|
||||||
"comment" : [{
|
];
|
||||||
token : "comment", // closing comment
|
|
||||||
regex : ".*?\\*\\/",
|
var ruleset = lang.copyArray( base_ruleset );
|
||||||
next : "start"
|
ruleset.unshift(
|
||||||
|
{
|
||||||
|
token : "rparen",
|
||||||
|
regex : "\}",
|
||||||
|
next: "start"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var media_ruleset = lang.copyArray( base_ruleset );
|
||||||
|
media_ruleset.unshift(
|
||||||
|
{
|
||||||
|
token : "rparen",
|
||||||
|
regex : "\}",
|
||||||
|
next: "media"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var base_comment = [
|
||||||
|
{
|
||||||
|
token : "comment", // comment spanning whole line
|
||||||
|
regex : ".+"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var comment = lang.copyArray( base_comment );
|
||||||
|
comment.unshift(
|
||||||
|
{
|
||||||
|
token : "comment", // closing comment
|
||||||
|
regex : ".*?\\*\\/",
|
||||||
|
next : "start"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var media_comment = lang.copyArray( base_comment );
|
||||||
|
media_comment.unshift(
|
||||||
|
{
|
||||||
|
token : "comment", // closing comment
|
||||||
|
regex : ".*?\\*\\/",
|
||||||
|
next : "media"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var ruleset_comment = lang.copyArray( base_comment );
|
||||||
|
ruleset_comment.unshift(
|
||||||
|
{
|
||||||
|
token : "comment", // closing comment
|
||||||
|
regex : ".*?\\*\\/",
|
||||||
|
next : "ruleset"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.$rules = {
|
||||||
|
"start" : [ {
|
||||||
|
token : "comment", // multi line comment
|
||||||
|
regex : "\\/\\*",
|
||||||
|
next : "comment"
|
||||||
}, {
|
}, {
|
||||||
token : "comment", // comment spanning whole line
|
token: "lparen",
|
||||||
regex : ".+"
|
regex: "{",
|
||||||
}]
|
next: "ruleset"
|
||||||
|
}, {
|
||||||
|
token: "string",
|
||||||
|
regex: "@media.*?{",
|
||||||
|
next: "media"
|
||||||
|
},{
|
||||||
|
token: "keyword",
|
||||||
|
regex: "#[a-zA-Z0-9-_]+"
|
||||||
|
},{
|
||||||
|
token: "variable",
|
||||||
|
regex: "\\.[a-zA-Z0-9-_]+"
|
||||||
|
},{
|
||||||
|
token: "string",
|
||||||
|
regex: ":[a-zA-Z0-9-_]+"
|
||||||
|
},{
|
||||||
|
token: "constant",
|
||||||
|
regex: "[a-zA-Z0-9-_]+"
|
||||||
|
}],
|
||||||
|
|
||||||
|
"media" : [ {
|
||||||
|
token : "comment", // multi line comment
|
||||||
|
regex : "\\/\\*",
|
||||||
|
next : "media_comment"
|
||||||
|
}, {
|
||||||
|
token: "lparen",
|
||||||
|
regex: "{",
|
||||||
|
next: "media_ruleset"
|
||||||
|
},{
|
||||||
|
token: "string",
|
||||||
|
regex: "}",
|
||||||
|
next: "start"
|
||||||
|
},{
|
||||||
|
token: "keyword",
|
||||||
|
regex: "#[a-zA-Z0-9-_]+"
|
||||||
|
},{
|
||||||
|
token: "variable",
|
||||||
|
regex: "\\.[a-zA-Z0-9-_]+"
|
||||||
|
},{
|
||||||
|
token: "string",
|
||||||
|
regex: ":[a-zA-Z0-9-_]+"
|
||||||
|
},{
|
||||||
|
token: "constant",
|
||||||
|
regex: "[a-zA-Z0-9-_]+"
|
||||||
|
}],
|
||||||
|
|
||||||
|
"comment" : comment,
|
||||||
|
|
||||||
|
"ruleset" : ruleset,
|
||||||
|
"ruleset_comment" : ruleset_comment,
|
||||||
|
|
||||||
|
"media_ruleset" : media_ruleset,
|
||||||
|
"media_comment" : media_comment
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue