From ac2629378fb0408223447617061102d2b0c53cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ITSheng=E3=81=AE=E5=8F=B0=E5=BC=8F=E6=9C=BA?= <453491931@qq.com> Date: Sun, 3 May 2020 17:27:47 +0800 Subject: [PATCH 1/6] pug: Improved class(named "attr-class") and id(named "attr-id") in tag detection, and added corresponding unit test. --- components/prism-pug.js | 8 ++++++++ tests/languages/pug/tag_feature.test | 24 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/components/prism-pug.js b/components/prism-pug.js index b1ecd942a3..3cf7802019 100644 --- a/components/prism-pug.js +++ b/components/prism-pug.js @@ -112,6 +112,14 @@ pattern: /(^[\t ]*)(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?:?/m, lookbehind: true, inside: { + 'attr-id': { + pattern: /(^[\t ]*(?!-)[\w\-.]*)#[\w\-]+/, + lookbehind: true + }, + 'attr-class': { + pattern: /(^[\t ]*(?!-)[\w\-#]*)\.[\w\-]+/, + lookbehind: true + }, 'attributes': [ { pattern: /&[^(]+\([^)]+\)/, diff --git a/tests/languages/pug/tag_feature.test b/tests/languages/pug/tag_feature.test index b4dbf0348d..9f07b5fa9b 100644 --- a/tests/languages/pug/tag_feature.test +++ b/tests/languages/pug/tag_feature.test @@ -13,6 +13,9 @@ a.button a#main-link #content +div#test-id.test-class1.test-class2 +.test-class1#test-id.test-class2 + a: span ---------------------------------------------------- @@ -83,10 +86,23 @@ a: span ]] ]], - ["tag", ["a.button"]], - ["tag", [".content"]], - ["tag", ["a#main-link"]], - ["tag", ["#content"]], + ["tag", [ + "a", + ["attr-class", ".button"]]], + ["tag", [["attr-class", ".content"]]], + ["tag", [ + "a", + ["attr-id", "#main-link"]]], + ["tag", [["attr-id", "#content"]]], + ["tag", [ + "div", + ["attr-id", "#test-id"], + ["attr-class", ".test-class1"], + ["attr-class", ".test-class2"]]], + ["tag", [ + ["attr-class", ".test-class1"], + ["attr-id", "#test-id"], + ["attr-class", ".test-class2"]]], ["tag", ["a", ["punctuation", ":"]]], ["tag", ["span"]] From c48d6545b47452742fa2f014888b6a513d3b1e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ITSheng=E3=81=AE=E5=8F=B0=E5=BC=8F=E6=9C=BA?= <453491931@qq.com> Date: Sun, 3 May 2020 21:41:14 +0800 Subject: [PATCH 2/6] pug: rewrite the better code, run "npx gulp" and commit ".min.js" --- components/prism-pug.js | 12 +++--------- components/prism-pug.min.js | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/components/prism-pug.js b/components/prism-pug.js index 3cf7802019..6860ded5dd 100644 --- a/components/prism-pug.js +++ b/components/prism-pug.js @@ -112,14 +112,6 @@ pattern: /(^[\t ]*)(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?:?/m, lookbehind: true, inside: { - 'attr-id': { - pattern: /(^[\t ]*(?!-)[\w\-.]*)#[\w\-]+/, - lookbehind: true - }, - 'attr-class': { - pattern: /(^[\t ]*(?!-)[\w\-#]*)\.[\w\-]+/, - lookbehind: true - }, 'attributes': [ { pattern: /&[^(]+\([^)]+\)/, @@ -138,7 +130,9 @@ } } ], - 'punctuation': /:/ + 'punctuation': /:/, + 'attr-id': /#[\w\-]+/, + 'attr-class': /\.[\w\-]+/ } }, 'code': [ diff --git a/components/prism-pug.min.js b/components/prism-pug.min.js index b116e79089..68ccecfdc0 100644 --- a/components/prism-pug.min.js +++ b/components/prism-pug.min.js @@ -1 +1 @@ -!function(e){e.languages.pug={comment:{pattern:/(^([\t ]*))\/\/.*(?:(?:\r?\n|\r)\2[\t ]+.+)*/m,lookbehind:!0},"multiline-script":{pattern:/(^([\t ]*)script\b.*\.[\t ]*)(?:(?:\r?\n|\r(?!\n))(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/m,lookbehind:!0,inside:e.languages.javascript},filter:{pattern:/(^([\t ]*)):.+(?:(?:\r?\n|\r(?!\n))(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/m,lookbehind:!0,inside:{"filter-name":{pattern:/^:[\w-]+/,alias:"variable"}}},"multiline-plain-text":{pattern:/(^([\t ]*)[\w\-#.]+\.[\t ]*)(?:(?:\r?\n|\r(?!\n))(?:\2[\t ]+.+|\s*?(?=\r?\n|\r)))+/m,lookbehind:!0},markup:{pattern:/(^[\t ]*)<.+/m,lookbehind:!0,inside:e.languages.markup},doctype:{pattern:/((?:^|\n)[\t ]*)doctype(?: .+)?/,lookbehind:!0},"flow-control":{pattern:/(^[\t ]*)(?:if|unless|else|case|when|default|each|while)\b(?: .+)?/m,lookbehind:!0,inside:{each:{pattern:/^each .+? in\b/,inside:{keyword:/\b(?:each|in)\b/,punctuation:/,/}},branch:{pattern:/^(?:if|unless|else|case|when|default|while)\b/,alias:"keyword"},rest:e.languages.javascript}},keyword:{pattern:/(^[\t ]*)(?:block|extends|include|append|prepend)\b.+/m,lookbehind:!0},mixin:[{pattern:/(^[\t ]*)mixin .+/m,lookbehind:!0,inside:{keyword:/^mixin/,function:/\w+(?=\s*\(|\s*$)/,punctuation:/[(),.]/}},{pattern:/(^[\t ]*)\+.+/m,lookbehind:!0,inside:{name:{pattern:/^\+\w+/,alias:"function"},rest:e.languages.javascript}}],script:{pattern:/(^[\t ]*script(?:(?:&[^(]+)?\([^)]+\))*[\t ]+).+/m,lookbehind:!0,inside:e.languages.javascript},"plain-text":{pattern:/(^[\t ]*(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?[\t ]+).+/m,lookbehind:!0},tag:{pattern:/(^[\t ]*)(?!-)[\w\-#.]*[\w\-](?:(?:&[^(]+)?\([^)]+\))*\/?:?/m,lookbehind:!0,inside:{attributes:[{pattern:/&[^(]+\([^)]+\)/,inside:e.languages.javascript},{pattern:/\([^)]+\)/,inside:{"attr-value":{pattern:/(=\s*)(?:\{[^}]*\}|[^,)\r\n]+)/,lookbehind:!0,inside:e.languages.javascript},"attr-name":/[\w-]+(?=\s*!?=|\s*[,)])/,punctuation:/[!=(),]+/}}],punctuation:/:/}},code:[{pattern:/(^[\t ]*(?:-|!?=)).+/m,lookbehind:!0,inside:e.languages.javascript}],punctuation:/[.\-!=|]+/};for(var t=[{filter:"atpl",language:"twig"},{filter:"coffee",language:"coffeescript"},"ejs","handlebars","less","livescript","markdown",{filter:"sass",language:"scss"},"stylus"],n={},a=0,i=t.length;a Date: Mon, 4 May 2020 14:24:11 +0800 Subject: [PATCH 3/6] Stylus: Fix comment-like grammar(/**/ or //) in property url() and string display --- components/prism-stylus.js | 10 ++++++- components/prism-stylus.min.js | 2 +- .../stylus/property-declaration_feature.test | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/components/prism-stylus.js b/components/prism-stylus.js index 256b70f77e..f3a4cd9ae8 100644 --- a/components/prism-stylus.js +++ b/components/prism-stylus.js @@ -1,6 +1,9 @@ (function (Prism) { var inside = { - 'url': /url\((["']?).*?\1\)/i, + 'url': { + pattern: /url\((["']?).*?\1\)/i, + greedy: true + }, 'string': { pattern: /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/, greedy: true @@ -78,6 +81,7 @@ 'property-declaration': { pattern: /((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)[^{\r\n]*(?:;|[^{\r\n,](?=$)(?!(?:\r?\n|\r)(?:\{|\2[ \t]+)))/m, lookbehind: true, + greedy: true, inside: { 'property': { pattern: /^[^\s:]+/, @@ -85,6 +89,10 @@ 'interpolation': inside.interpolation } }, + 'comment': { + pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, + lookbehind: true + }, rest: inside } }, diff --git a/components/prism-stylus.min.js b/components/prism-stylus.min.js index 08309271e9..02045fb092 100644 --- a/components/prism-stylus.min.js +++ b/components/prism-stylus.min.js @@ -1 +1 @@ -!function(n){var t={url:/url\((["']?).*?\1\)/i,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,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(n){var t={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}},comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},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 diff --git a/tests/languages/stylus/property-declaration_feature.test b/tests/languages/stylus/property-declaration_feature.test index 275eb43d92..ff42f035dd 100644 --- a/tests/languages/stylus/property-declaration_feature.test +++ b/tests/languages/stylus/property-declaration_feature.test @@ -10,6 +10,12 @@ background-{foo}: bar; div {foo} bar +comment + content 'http://www.example.com' // comment + background url(http://example.com) /* comment */ + background /* comment */ url("http://example.com") + content '/* this is string not comment */' + ---------------------------------------------------- [ @@ -44,6 +50,27 @@ div ]] ]], " bar" + ]], + + ["selector", ["comment"]], + ["property-declaration", [ + ["property", ["content"]], + ["string", "'http://www.example.com'"], + ["comment", "// comment"] + ]], + ["property-declaration", [ + ["property", ["background"]], + ["url", "url(http://example.com)"], + ["comment", "/* comment */"] + ]], + ["property-declaration", [ + ["property", ["background"]], + ["comment", "/* comment */"], + ["url", "url(\"http://example.com\")"] + ]], + ["property-declaration", [ + ["property", ["content"]], + ["string", "'/* this is string not comment */'"] ]] ] From c3da26ff4867a2716afba08c0ff34ac8fdd3e8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ITSheng=E3=81=AE=E5=8F=B0=E5=BC=8F=E6=9C=BA?= <453491931@qq.com> Date: Mon, 4 May 2020 22:19:22 +0800 Subject: [PATCH 4/6] Stylus: replace the `comment` in the `inside` object --- components/prism-stylus.js | 8 ++++---- components/prism-stylus.min.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/prism-stylus.js b/components/prism-stylus.js index f3a4cd9ae8..9ebc873632 100644 --- a/components/prism-stylus.js +++ b/components/prism-stylus.js @@ -1,5 +1,9 @@ (function (Prism) { var inside = { + 'comment': { + pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, + lookbehind: true + }, 'url': { pattern: /url\((["']?).*?\1\)/i, greedy: true @@ -89,10 +93,6 @@ 'interpolation': inside.interpolation } }, - 'comment': { - pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, - lookbehind: true - }, rest: inside } }, diff --git a/components/prism-stylus.min.js b/components/prism-stylus.min.js index 02045fb092..002e32893d 100644 --- a/components/prism-stylus.min.js +++ b/components/prism-stylus.min.js @@ -1 +1 @@ -!function(n){var t={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}},comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0},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(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 From 2cb260f0dc192f9f8dacfbb35c729adc981cc435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ITSheng=E3=81=AE=E5=8F=B0=E5=BC=8F=E6=9C=BA?= <453491931@qq.com> Date: Wed, 6 May 2020 20:51:14 +0800 Subject: [PATCH 5/6] Stylus: Add `color`, `entity`, `unit`, change `number` and `operator` in `inside` object, Fix relational tests. --- components/prism-stylus.js | 28 +++++++++++++++++-- components/prism-stylus.min.js | 2 +- .../stylus+pug/stylus_inclusion.test | 2 +- tests/languages/stylus/func_feature.test | 2 +- tests/languages/stylus/important_feature.test | 2 +- tests/languages/stylus/number_feature.test | 6 ++-- .../stylus/property-declaration_feature.test | 6 ++-- tests/languages/stylus/selector_feature.test | 10 +++---- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/components/prism-stylus.js b/components/prism-stylus.js index 9ebc873632..7a732b7ea8 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..7230fc8222 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..cdf0aef31e 100644 --- a/tests/languages/stylus/property-declaration_feature.test +++ b/tests/languages/stylus/property-declaration_feature.test @@ -21,13 +21,13 @@ 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", ";"] ]], ["selector", ["div ", ["punctuation", "{"]]], ["property-declaration", [ 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"]]] ] ---------------------------------------------------- From 2d162ff0ea17ddb494aea4f34dda84c60da6c752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ITSheng=E3=81=AE=E5=8F=B0=E5=BC=8F=E6=9C=BA?= <453491931@qq.com> Date: Thu, 7 May 2020 16:03:20 +0800 Subject: [PATCH 6/6] Stylus: remove extra `|` in `number` property and add relative tests. --- components/prism-stylus.js | 2 +- components/prism-stylus.min.js | 2 +- tests/languages/stylus/property-declaration_feature.test | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/prism-stylus.js b/components/prism-stylus.js index 7a732b7ea8..fb738429e1 100644 --- a/components/prism-stylus.js +++ b/components/prism-stylus.js @@ -5,7 +5,7 @@ }; // 123 -123 .123 -.123 12.3 -12.3 var number = { - pattern: /(^|[^\w.-]|)-?\d*\.?\d+/, + pattern: /(^|[^\w.-])-?\d*\.?\d+/, lookbehind: true }; diff --git a/components/prism-stylus.min.js b/components/prism-stylus.min.js index 7230fc8222..2c63c58159 100644 --- a/components/prism-stylus.min.js +++ b/components/prism-stylus.min.js @@ -1 +1 @@ -!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 +!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/property-declaration_feature.test b/tests/languages/stylus/property-declaration_feature.test index cdf0aef31e..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; @@ -29,6 +30,8 @@ comment ["property-declaration", [ ["property", ["background"]], ["punctuation", ":"], ["color", "blue"], ["punctuation", ";"] ]], + ["property-declaration", [ + ["property", ["animation-name"]], " test1", ["punctuation", ","], " animation4"]], ["selector", ["div ", ["punctuation", "{"]]], ["property-declaration", [ ["property", [