diff --git a/components/prism-stylus.js b/components/prism-stylus.js index 9ebc873632..fb738429e1 100644 --- a/components/prism-stylus.js +++ b/components/prism-stylus.js @@ -1,4 +1,14 @@ (function (Prism) { + var unit = { + pattern: /(\d)(?:%|[a-z]+)/, + lookbehind: true + }; + // 123 -123 .123 -.123 12.3 -12.3 + var number = { + pattern: /(^|[^\w.-])-?\d*\.?\d+/, + lookbehind: true + }; + var inside = { 'comment': { pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, @@ -20,13 +30,27 @@ lookbehind: true }, 'hexcode': /#[\da-f]{3,6}/i, - 'number': /\b\d+(?:\.\d+)?%?/, + 'color': [ + /\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i, + { + pattern: /\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i, + inside: { + 'unit': unit, + 'number': number, + 'function': /[\w-]+(?=\()/, + 'punctuation': /[(),]/ + } + } + ], + 'entity': /\\[\da-f]{1,8}/i, + 'unit': unit, 'boolean': /\b(?:true|false)\b/, 'operator': [ // We want non-word chars around "-" because it is // accepted in property names. - /~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.+|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/ + /~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.{2,3}|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/ ], + 'number': number, 'punctuation': /[{}()\[\];:,]/ }; diff --git a/components/prism-stylus.min.js b/components/prism-stylus.min.js index 002e32893d..2c63c58159 100644 --- a/components/prism-stylus.min.js +++ b/components/prism-stylus.min.js @@ -1 +1 @@ -!function(n){var t={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},url:{pattern:/url\((["']?).*?\1\)/i,greedy:!0},string:{pattern:/("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,greedy:!0},interpolation:null,func:null,important:/\B!(?:important|optional)\b/i,keyword:{pattern:/(^|\s+)(?:(?:if|else|for|return|unless)(?=\s+|$)|@[\w-]+)/,lookbehind:!0},hexcode:/#[\da-f]{3,6}/i,number:/\b\d+(?:\.\d+)?%?/,boolean:/\b(?:true|false)\b/,operator:[/~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.+|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/],punctuation:/[{}()\[\];:,]/};t.interpolation={pattern:/\{[^\r\n}:]+\}/,alias:"variable",inside:{delimiter:{pattern:/^{|}$/,alias:"punctuation"},rest:t}},t.func={pattern:/[\w-]+\([^)]*\).*/,inside:{function:/^[^(]+/,rest:t}},n.languages.stylus={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"atrule-declaration":{pattern:/(^\s*)@.+/m,lookbehind:!0,inside:{atrule:/^@[\w-]+/,rest:t}},"variable-declaration":{pattern:/(^[ \t]*)[\w$-]+\s*.?=[ \t]*(?:(?:\{[^}]*\}|.+)|$)/m,lookbehind:!0,inside:{variable:/^\S+/,rest:t}},statement:{pattern:/(^[ \t]*)(?:if|else|for|return|unless)[ \t]+.+/m,lookbehind:!0,inside:{keyword:/^\S+/,rest:t}},"property-declaration":{pattern:/((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)[^{\r\n]*(?:;|[^{\r\n,](?=$)(?!(?:\r?\n|\r)(?:\{|\2[ \t]+)))/m,lookbehind:!0,greedy:!0,inside:{property:{pattern:/^[^\s:]+/,inside:{interpolation:t.interpolation}},rest:t}},selector:{pattern:/(^[ \t]*)(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\))?|\{[^}\r\n]+\})+)(?:(?:\r?\n|\r)(?:\1(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\))?|\{[^}\r\n]+\})+)))*(?:,$|\{|(?=(?:\r?\n|\r)(?:\{|\1[ \t]+)))/m,lookbehind:!0,inside:{interpolation:t.interpolation,punctuation:/[{},]/}},func:t.func,string:t.string,interpolation:t.interpolation,punctuation:/[{}()\[\];:.]/}}(Prism); \ No newline at end of file +!function(e){var n={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},r={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0},i={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},url:{pattern:/url\((["']?).*?\1\)/i,greedy:!0},string:{pattern:/("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,greedy:!0},interpolation:null,func:null,important:/\B!(?:important|optional)\b/i,keyword:{pattern:/(^|\s+)(?:(?:if|else|for|return|unless)(?=\s+|$)|@[\w-]+)/,lookbehind:!0},hexcode:/#[\da-f]{3,6}/i,color:[/\b(?:AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGr[ae]y|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGr[ae]y|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGr[ae]y|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|GoldenRod|Gr[ae]y|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGr[ae]y|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGr[ae]y|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGr[ae]y|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Transparent|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen)\b/i,{pattern:/\b(?:rgb|hsl)\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\)\B|\b(?:rgb|hsl)a\(\s*\d{1,3}\s*,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*,\s*(?:0|0?\.\d+|1)\s*\)\B/i,inside:{unit:n,number:r,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:n,boolean:/\b(?:true|false)\b/,operator:[/~|[+!\/%<>?=]=?|[-:]=|\*[*=]?|\.{2,3}|&&|\|\||\B-\B|\b(?:and|in|is(?: a| defined| not|nt)?|not|or)\b/],number:r,punctuation:/[{}()\[\];:,]/};i.interpolation={pattern:/\{[^\r\n}:]+\}/,alias:"variable",inside:{delimiter:{pattern:/^{|}$/,alias:"punctuation"},rest:i}},i.func={pattern:/[\w-]+\([^)]*\).*/,inside:{function:/^[^(]+/,rest:i}},e.languages.stylus={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},"atrule-declaration":{pattern:/(^\s*)@.+/m,lookbehind:!0,inside:{atrule:/^@[\w-]+/,rest:i}},"variable-declaration":{pattern:/(^[ \t]*)[\w$-]+\s*.?=[ \t]*(?:(?:\{[^}]*\}|.+)|$)/m,lookbehind:!0,inside:{variable:/^\S+/,rest:i}},statement:{pattern:/(^[ \t]*)(?:if|else|for|return|unless)[ \t]+.+/m,lookbehind:!0,inside:{keyword:/^\S+/,rest:i}},"property-declaration":{pattern:/((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)[^{\r\n]*(?:;|[^{\r\n,](?=$)(?!(?:\r?\n|\r)(?:\{|\2[ \t]+)))/m,lookbehind:!0,greedy:!0,inside:{property:{pattern:/^[^\s:]+/,inside:{interpolation:i.interpolation}},rest:i}},selector:{pattern:/(^[ \t]*)(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\))?|\{[^}\r\n]+\})+)(?:(?:\r?\n|\r)(?:\1(?:(?=\S)(?:[^{}\r\n:()]|::?[\w-]+(?:\([^)\r\n]*\))?|\{[^}\r\n]+\})+)))*(?:,$|\{|(?=(?:\r?\n|\r)(?:\{|\1[ \t]+)))/m,lookbehind:!0,inside:{interpolation:i.interpolation,punctuation:/[{},]/}},func:i.func,string:i.string,interpolation:i.interpolation,punctuation:/[{}()\[\];:.]/}}(Prism); \ No newline at end of file diff --git a/tests/languages/stylus+pug/stylus_inclusion.test b/tests/languages/stylus+pug/stylus_inclusion.test index 3c7c8d2574..d154ab2e75 100644 --- a/tests/languages/stylus+pug/stylus_inclusion.test +++ b/tests/languages/stylus+pug/stylus_inclusion.test @@ -10,7 +10,7 @@ ["variable", "font-size"], ["operator", "="], ["number", "14"], - "px" + ["unit", "px"] ]] ]] ] diff --git a/tests/languages/stylus/func_feature.test b/tests/languages/stylus/func_feature.test index 7f2c346774..59ad2362c0 100644 --- a/tests/languages/stylus/func_feature.test +++ b/tests/languages/stylus/func_feature.test @@ -33,7 +33,7 @@ form input[type=button] ["function", "border-radius"], ["punctuation", "("], ["number", "5"], - "px", + ["unit", "px"], ["punctuation", ")"] ]], ["property-declaration", [ diff --git a/tests/languages/stylus/important_feature.test b/tests/languages/stylus/important_feature.test index 225c1e0539..44c9fdbe8f 100644 --- a/tests/languages/stylus/important_feature.test +++ b/tests/languages/stylus/important_feature.test @@ -7,7 +7,7 @@ color: red !important ["property-declaration", [ ["property", ["color"]], ["punctuation", ":"], - " red ", + ["color", "red"], ["important", "!important"] ]], ["atrule-declaration", [ diff --git a/tests/languages/stylus/number_feature.test b/tests/languages/stylus/number_feature.test index f3a0710903..61229b92ac 100644 --- a/tests/languages/stylus/number_feature.test +++ b/tests/languages/stylus/number_feature.test @@ -18,12 +18,14 @@ bar = 1.5% ["property-declaration", [ ["property", ["width"]], ["punctuation", ":"], - ["number", "23%"] + ["number", "23"], + ["unit", "%"] ]], ["variable-declaration", [ ["variable", "bar"], ["operator", "="], - ["number", "1.5%"] + ["number", "1.5"], + ["unit", "%"] ]] ] diff --git a/tests/languages/stylus/property-declaration_feature.test b/tests/languages/stylus/property-declaration_feature.test index ff42f035dd..d4cd649639 100644 --- a/tests/languages/stylus/property-declaration_feature.test +++ b/tests/languages/stylus/property-declaration_feature.test @@ -2,6 +2,7 @@ div width 40px color: red background: blue; + animation-name test1, animation4 div { background-{foo}: bar; @@ -21,14 +22,16 @@ comment [ ["selector", ["div"]], ["property-declaration", [ - ["property", ["width"]], ["number", "40"], "px" + ["property", ["width"]], ["number", "40"], ["unit", "px"] ]], ["property-declaration", [ - ["property", ["color"]], ["punctuation", ":"], " red" + ["property", ["color"]], ["punctuation", ":"], ["color", "red"] ]], ["property-declaration", [ - ["property", ["background"]], ["punctuation", ":"], " blue", ["punctuation", ";"] + ["property", ["background"]], ["punctuation", ":"], ["color", "blue"], ["punctuation", ";"] ]], + ["property-declaration", [ + ["property", ["animation-name"]], " test1", ["punctuation", ","], " animation4"]], ["selector", ["div ", ["punctuation", "{"]]], ["property-declaration", [ ["property", [ diff --git a/tests/languages/stylus/selector_feature.test b/tests/languages/stylus/selector_feature.test index 1908c4bed7..3868dfcaa3 100644 --- a/tests/languages/stylus/selector_feature.test +++ b/tests/languages/stylus/selector_feature.test @@ -22,15 +22,15 @@ color red [ ["selector", ["div\r\nspan[foo=bar]"]], - ["property-declaration", [["property", ["color"]], " red"]], + ["property-declaration", [["property", ["color"]], ["color", "red"]]], ["selector", ["div input", ["punctuation", ","], "\r\ninput:nth-child(2n)"]], - ["property-declaration", [["property", ["color"]], " red"]], + ["property-declaration", [["property", ["color"]], ["color", "red"]]], ["selector", ["#foo"]], ["selector", [".bar::before"]], - ["property-declaration", [["property", ["color"]], " red"]], + ["property-declaration", [["property", ["color"]], ["color", "red"]]], ["selector", ["#foo"]], ["selector", [".bar ", ["punctuation", "{"]]], - ["property-declaration", [["property", ["color"]], " red"]], + ["property-declaration", [["property", ["color"]], ["color", "red"]]], ["punctuation", "}"], ["selector", [ ["interpolation", [ @@ -41,7 +41,7 @@ color red ]], ":hover" ]], - ["property-declaration", [["property", ["color"]], " red"]] + ["property-declaration", [["property", ["color"]], ["color", "red"]]] ] ----------------------------------------------------