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 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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", [ From a37cd5efcf3cc3bd308d63f0aa1d6f6786c90fe2 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: Fri, 8 May 2020 02:59:48 +0800 Subject: [PATCH 07/12] Stylus: Put the `comment` token behind the `string` token and set the `greedy` property to `true` --- components/prism-stylus.js | 11 ++++++----- components/prism-stylus.min.js | 2 +- .../stylus/atrule-declaration_feature.test | 13 +++++++++++++ tests/languages/stylus/keyword_feature.test | 8 ++++++++ tests/languages/stylus/selector_feature.test | 7 ++++++- .../stylus/variable-declaration_feature.test | 7 +++++++ 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/components/prism-stylus.js b/components/prism-stylus.js index fb738429e1..18d014dbef 100644 --- a/components/prism-stylus.js +++ b/components/prism-stylus.js @@ -74,10 +74,6 @@ }; Prism.languages.stylus = { - 'comment': { - pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, - lookbehind: true - }, 'atrule-declaration': { pattern: /(^\s*)@.+/m, lookbehind: true, @@ -109,7 +105,6 @@ '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:]+/, @@ -131,12 +126,18 @@ lookbehind: true, inside: { 'interpolation': inside.interpolation, + 'comment': inside.comment, 'punctuation': /[{},]/ } }, 'func': inside.func, 'string': inside.string, + 'comment': { + pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/, + lookbehind: true, + greedy: true + }, 'interpolation': inside.interpolation, 'punctuation': /[{}()\[\];:.]/ }; diff --git a/components/prism-stylus.min.js b/components/prism-stylus.min.js index 2c63c58159..f70528cf87 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={"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,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,comment:i.comment,punctuation:/[{},]/}},func:i.func,string:i.string,comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,lookbehind:!0,greedy:!0},interpolation:i.interpolation,punctuation:/[{}()\[\];:.]/}}(Prism); \ No newline at end of file diff --git a/tests/languages/stylus/atrule-declaration_feature.test b/tests/languages/stylus/atrule-declaration_feature.test index d0e6505d5f..156a553020 100644 --- a/tests/languages/stylus/atrule-declaration_feature.test +++ b/tests/languages/stylus/atrule-declaration_feature.test @@ -3,6 +3,8 @@ @font-face { @keyframes { @media (max-{foo}: bar) +@namespace url(http://www.w3.org/1999/xhtml) // comment +@namespace svg url(http://www.w3.org/2000/svg) // comment ---------------------------------------------------- @@ -23,6 +25,17 @@ ["punctuation", ":"], " bar", ["punctuation", ")"] + ]], + ["atrule-declaration", [ + ["atrule", "@namespace"], + ["url", "url(http://www.w3.org/1999/xhtml)"], + ["comment", "// comment"] + ]], + ["atrule-declaration", [ + ["atrule", "@namespace"], + " svg ", + ["url", "url(http://www.w3.org/2000/svg)"], + ["comment", "// comment"] ]] ] diff --git a/tests/languages/stylus/keyword_feature.test b/tests/languages/stylus/keyword_feature.test index 5182775191..f5ebb4f6f5 100644 --- a/tests/languages/stylus/keyword_feature.test +++ b/tests/languages/stylus/keyword_feature.test @@ -2,6 +2,7 @@ for i in 1..5 if a == 3 z-index: 1 unless @z-index; return pair[1] if pair[0] == key for pair in hash +if url == "http://example.com" // comment ---------------------------------------------------- @@ -36,6 +37,13 @@ return pair[1] if pair[0] == key for pair in hash ["operator", "=="], " key ", ["keyword", "for"], " pair ", ["operator", "in"], " hash" + ]], + ["statement", [ + ["keyword", "if"], + " url ", + ["operator", "=="], + ["string", "\"http://example.com\""], + ["comment", "// comment"] ]] ] diff --git a/tests/languages/stylus/selector_feature.test b/tests/languages/stylus/selector_feature.test index 3868dfcaa3..50912ea2f6 100644 --- a/tests/languages/stylus/selector_feature.test +++ b/tests/languages/stylus/selector_feature.test @@ -18,6 +18,9 @@ color red {foo} {bar}:hover color red +div // comment + display inline-block // comment + ---------------------------------------------------- [ @@ -41,7 +44,9 @@ color red ]], ":hover" ]], - ["property-declaration", [["property", ["color"]], ["color", "red"]]] + ["property-declaration", [["property", ["color"]], ["color", "red"]]], + ["selector", ["div ", ["comment", "// comment"]]], + ["property-declaration", [["property", ["display"]], " inline-block ", ["comment", "// comment"]]] ] ---------------------------------------------------- diff --git a/tests/languages/stylus/variable-declaration_feature.test b/tests/languages/stylus/variable-declaration_feature.test index 1d68f9dfe0..2e98e4fb0d 100644 --- a/tests/languages/stylus/variable-declaration_feature.test +++ b/tests/languages/stylus/variable-declaration_feature.test @@ -2,6 +2,7 @@ foo = 'bar' a = 4 bar-baz = 5 a += 8 +url = "http://example.com" // comment ---------------------------------------------------- @@ -25,6 +26,12 @@ a += 8 ["variable", "a"], ["operator", "+="], ["number", "8"] + ]], + ["variable-declaration", [ + ["variable", "url"], + ["operator", "="], + ["string", "\"http://example.com\""], + ["comment", "// comment"] ]] ] From 49a6edac011f03844300baeda8c439628a0f40df 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: Fri, 8 May 2020 12:24:10 +0800 Subject: [PATCH 08/12] CSS Extra: (1) rename `attr-name`, `attr-value` (2) change `pseudo-class` token (3) add `tag`, `selector-list`, `combinator` token --- components/prism-css-extras.js | 51 +++-- components/prism-css-extras.min.js | 2 +- .../css!+css-extras/number_feature.test | 2 +- .../selector_attribute_feature.test | 70 +++---- .../css!+css-extras/selector_feature.test | 21 ++- .../selector_n-th_feature.test | 176 ++++++++++-------- .../selector_pseudo-class_feature.test | 124 ++++++------ .../css!+css-extras/variable_feature.test | 2 +- 8 files changed, 245 insertions(+), 203 deletions(-) diff --git a/components/prism-css-extras.js b/components/prism-css-extras.js index 1b6ab8c027..81c21beff4 100644 --- a/components/prism-css-extras.js +++ b/components/prism-css-extras.js @@ -7,9 +7,32 @@ pattern: Prism.languages.css.selector, inside: selectorInside = { 'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/, - 'pseudo-class': /:[-\w]+/, + 'pseudo-class': { + pattern: /:[-\w]+((\([^\(]*\([^\)]*\)[^\)]*\))|(\(.*?\)))?/, + greedy: true, + inside: { + 'n-th': [ + { + pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/, + lookbehind: true, + inside: { + 'number': /[\dn]+/, + 'operator': /[+-]/ + } + }, + { + pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i, + lookbehind: true + } + ], + 'punctuation': /[()]/, + } + }, 'class': /\.[-:.\w]+/, 'id': /#[-:.\w]+/, + 'tag': /[-\w]+/, + 'selector-list': /,/, + 'combinator': />|\+|~|(\|\|)]/, 'attribute': { pattern: RegExp('\\[(?:[^[\\]"\']|' + string.source + ')*\\]'), greedy: true, @@ -27,11 +50,11 @@ 'punctuation': /\|$/ } }, - 'attribute': { + 'attr-name': { pattern: /^(\s*)[-\w\xA0-\uFFFF]+/, lookbehind: true }, - 'value': [ + 'attr-value': [ string, { pattern: /(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/, @@ -41,24 +64,16 @@ 'operator': /[|~*^$]?=/ } }, - 'n-th': [ - { - pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/, - lookbehind: true, - inside: { - 'number': /[\dn]+/, - 'operator': /[+-]/ - } - }, - { - pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i, - lookbehind: true - } - ], - 'punctuation': /[()]/ } }; + // TODO: support 'pseudo-class' and 'tag' token + for (var token in selectorInside) { + if (token !== 'pseudo-class' && token !== 'tag') { + selectorInside['pseudo-class'].inside[token] = selectorInside[token]; + } + } + Prism.languages.css['atrule'].inside['selector-function-argument'].inside = selectorInside; Prism.languages.insertBefore('css', 'property', { diff --git a/components/prism-css-extras.min.js b/components/prism-css-extras.min.js index 00ed486bf1..cccd1443b6 100644 --- a/components/prism-css-extras.min.js +++ b/components/prism-css-extras.min.js @@ -1 +1 @@ -!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},attribute:{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},value:[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],punctuation:/[()]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var r={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},i={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:r,number:i,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:i})}(Prism); \ No newline at end of file +!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;for(var r in e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":{pattern:/:[-\w]+((\([^\(]*\([^\)]*\)[^\)]*\))|(\(.*?\)))?/,greedy:!0,inside:{"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],punctuation:/[()]/}},class:/\.[-:.\w]+/,id:/#[-:.\w]+/,tag:/[-\w]+/,"selector-list":/,/,combinator:/>|\+|~|(\|\|)]/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}}}},a)"pseudo-class"!==r&&"tag"!==r&&(a["pseudo-class"].inside[r]=a[r]);e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var i={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},t={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:i,number:t,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:i,number:t})}(Prism); \ No newline at end of file diff --git a/tests/languages/css!+css-extras/number_feature.test b/tests/languages/css!+css-extras/number_feature.test index 1ac34b99ca..6e71d4b5ae 100644 --- a/tests/languages/css!+css-extras/number_feature.test +++ b/tests/languages/css!+css-extras/number_feature.test @@ -24,7 +24,7 @@ foo { ["comment", "/* complex example */"], ["selector", [ - "foo" + ["tag", "foo"] ]], ["punctuation", "{"], diff --git a/tests/languages/css!+css-extras/selector_attribute_feature.test b/tests/languages/css!+css-extras/selector_attribute_feature.test index 25d1259f2b..fe2587b7a6 100644 --- a/tests/languages/css!+css-extras/selector_attribute_feature.test +++ b/tests/languages/css!+css-extras/selector_attribute_feature.test @@ -28,7 +28,7 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["punctuation", "]"] ]] ]], @@ -38,9 +38,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -50,9 +50,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "\"val\""], + ["attr-value", "\"val\""], ["punctuation", "]"] ]] ]], @@ -62,9 +62,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "'val'"], + ["attr-value", "'val'"], ["punctuation", "]"] ]] ]], @@ -74,9 +74,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "|="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -86,9 +86,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "~="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -98,9 +98,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "|="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -110,9 +110,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "^="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -122,9 +122,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "$="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -134,9 +134,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "*="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -150,7 +150,7 @@ "foo", ["punctuation", "|"] ]], - ["attribute", "attr"], + ["attr-name", "attr"], ["punctuation", "]"] ]], ["attribute", [ @@ -159,7 +159,7 @@ "*", ["punctuation", "|"] ]], - ["attribute", "attr"], + ["attr-name", "attr"], ["punctuation", "]"] ]], ["attribute", [ @@ -167,7 +167,7 @@ ["namespace", [ ["punctuation", "|"] ]], - ["attribute", "attr"], + ["attr-name", "attr"], ["punctuation", "]"] ]] ]], @@ -181,9 +181,9 @@ "foo", ["punctuation", "|"] ]], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "|="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -193,9 +193,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "val"], + ["attr-value", "val"], ["case-sensitivity", "i"], ["punctuation", "]"] ]] @@ -206,9 +206,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "\"val\""], + ["attr-value", "\"val\""], ["case-sensitivity", "S"], ["punctuation", "]"] ]] @@ -219,7 +219,7 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["punctuation", "]"] ]] ]], @@ -229,9 +229,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "val"], + ["attr-value", "val"], ["punctuation", "]"] ]] ]], @@ -241,9 +241,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "val"], + ["attr-value", "val"], ["case-sensitivity", "i"], ["punctuation", "]"] ]] @@ -254,9 +254,9 @@ ["selector", [ ["attribute", [ ["punctuation", "["], - ["attribute", "attr"], + ["attr-name", "attr"], ["operator", "="], - ["value", "\"i#m :not(a.class)\""], + ["attr-value", "\"i#m :not(a.class)\""], ["punctuation", "]"] ]] ]], diff --git a/tests/languages/css!+css-extras/selector_feature.test b/tests/languages/css!+css-extras/selector_feature.test index d42ec7faa6..e81057427a 100644 --- a/tests/languages/css!+css-extras/selector_feature.test +++ b/tests/languages/css!+css-extras/selector_feature.test @@ -7,35 +7,44 @@ foo#bar { #foo > .bar:hover:after { +span, +div { + ---------------------------------------------------- [ ["selector", [ - "foo", + ["tag", "foo"], ["pseudo-element", ":after"] ]], ["punctuation", "{"], ["selector", [ - "foo", + ["tag", "foo"], ["pseudo-element", "::first-letter"] ]], ["punctuation", "{"], ["selector", [ - "foo", + ["tag", "foo"], ["class", ".bar"] ]], ["punctuation", "{"], ["selector", [ - "foo", + ["tag", "foo"], ["id", "#bar"] ]], ["punctuation", "{"], ["selector", [ ["id", "#foo"], - " > ", + ["combinator", ">"], ["class", ".bar"], - ["pseudo-class", ":hover"], + ["pseudo-class", [":hover"]], ["pseudo-element", ":after"] + ]], ["punctuation", "{"], + + ["selector", [ + ["tag", "span"], + ["selector-list", ","], + ["tag", "div"] ]], ["punctuation", "{"] ] diff --git a/tests/languages/css!+css-extras/selector_n-th_feature.test b/tests/languages/css!+css-extras/selector_n-th_feature.test index 64e5aa7bb5..0c27de2ef1 100644 --- a/tests/languages/css!+css-extras/selector_n-th_feature.test +++ b/tests/languages/css!+css-extras/selector_n-th_feature.test @@ -1,82 +1,94 @@ -:nth-child(2n+1) {} -:nth-child(+2n - 1) {} -:nth-child(2n) {} -:nth-child(+5) {} -:nth-child(even) {} -:nth-child(odd) {} - ----------------------------------------------------- - -[ - ["selector", [ - ["pseudo-class", ":nth-child"], - ["punctuation", "("], - ["n-th", [ - ["number", "2n"], - ["operator", "+"], - ["number", "1"] - ]], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", ":nth-child"], - ["punctuation", "("], - ["n-th", [ - ["operator", "+"], - ["number", "2n"], - ["operator", "-"], - ["number", "1"] - ]], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", ":nth-child"], - ["punctuation", "("], - ["n-th", [ - ["number", "2n"] - ]], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", ":nth-child"], - ["punctuation", "("], - ["n-th", [ - ["operator", "+"], - ["number", "5"] - ]], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", ":nth-child"], - ["punctuation", "("], - ["n-th", "even"], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", ":nth-child"], - ["punctuation", "("], - ["n-th", "odd"], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"] -] - ----------------------------------------------------- - -Checks for n-th expressions. +:nth-child(2n+1) {} +:nth-child(+2n - 1) {} +:nth-child(2n) {} +:nth-child(+5) {} +:nth-child(even) {} +:nth-child(odd) {} + +---------------------------------------------------- + +[ + ["selector", [ + ["pseudo-class", [ + ":nth-child", + ["punctuation", "("], + ["n-th", [ + ["number", "2n"], + ["operator", "+"], + ["number", "1"] + ]], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", [ + ":nth-child", + ["punctuation", "("], + ["n-th", [ + ["operator", "+"], + ["number", "2n"], + ["operator", "-"], + ["number", "1"] + ]], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", [ + ":nth-child", + ["punctuation", "("], + ["n-th", [ + ["number", "2n"] + ]], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", [ + ":nth-child", + ["punctuation", "("], + ["n-th", [ + ["operator", "+"], + ["number", "5"] + ]], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", [ + ":nth-child", + ["punctuation", "("], + ["n-th", "even"], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", [ + ":nth-child", + ["punctuation", "("], + ["n-th", "odd"], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"] +] + +---------------------------------------------------- + +Checks for n-th expressions. diff --git a/tests/languages/css!+css-extras/selector_pseudo-class_feature.test b/tests/languages/css!+css-extras/selector_pseudo-class_feature.test index e4dfe15183..6fd260cab6 100644 --- a/tests/languages/css!+css-extras/selector_pseudo-class_feature.test +++ b/tests/languages/css!+css-extras/selector_pseudo-class_feature.test @@ -1,59 +1,65 @@ -foo:hover {} - -:lang(en) {} - -.bar:not(baz:hover):not(.foo) {} - -:where(p:not(.class)) {} - ----------------------------------------------------- - -[ - ["selector", [ - "foo", - ["pseudo-class", ":hover"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", ":lang"], - ["punctuation", "("], - "en", - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["class", ".bar"], - ["pseudo-class", ":not"], - ["punctuation", "("], - "baz", - ["pseudo-class", ":hover"], - ["punctuation", ")"], - ["pseudo-class", ":not"], - ["punctuation", "("], - ["class", ".foo"], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", ":where"], - ["punctuation", "("], - "p", - ["pseudo-class", ":not"], - ["punctuation", "("], - ["class", ".class"], - ["punctuation", ")"], - ["punctuation", ")"] - ]], - ["punctuation", "{"], - ["punctuation", "}"] -] - ----------------------------------------------------- - -Checks for pseudo-classes inside selectors. +foo:hover {} + +:lang(en) {} + +.bar:not(baz:hover):not(.foo) {} + +:where(p:not(.class)) {} + +---------------------------------------------------- + +[ + ["selector", [ + ["tag", "foo"], + ["pseudo-class", [":hover"]] + ]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", [ + ":lang", + ["punctuation", "("], + "en", + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["class", ".bar"], + ["pseudo-class", [ + ":not", + ["punctuation", "("], + "baz:hover", + ["punctuation", ")"] + ]], + ["pseudo-class", [ + ":not", + ["punctuation", "("], + ["class", ".foo"], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", [ + ":where", + ["punctuation", "("], + "p:not", + ["punctuation", "("], + ["class", ".class"], + ["punctuation", ")"], + ["punctuation", ")"] + ] + ]]], + ["punctuation", "{"], + ["punctuation", "}"] +] + +---------------------------------------------------- + +Checks for pseudo-classes inside selectors. diff --git a/tests/languages/css!+css-extras/variable_feature.test b/tests/languages/css!+css-extras/variable_feature.test index 657688fcd1..5f673573de 100644 --- a/tests/languages/css!+css-extras/variable_feature.test +++ b/tests/languages/css!+css-extras/variable_feature.test @@ -10,7 +10,7 @@ calc(100% - var(--margin-size) * 2) ---------------------------------------------------- [ - ["selector", ["element"]], + ["selector", [["tag", "element"]]], ["punctuation", "{"], ["variable", "--foo"], ["punctuation", ":"], From fb011be706e23f9c169e3a8cfee7c71d9106d1fe 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: Fri, 8 May 2020 13:16:42 +0800 Subject: [PATCH 09/12] CSS Extra: add `?:` in regex to pass the test. --- components/prism-css-extras.js | 4 ++-- components/prism-css-extras.min.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/prism-css-extras.js b/components/prism-css-extras.js index 81c21beff4..6c035d0814 100644 --- a/components/prism-css-extras.js +++ b/components/prism-css-extras.js @@ -8,7 +8,7 @@ inside: selectorInside = { 'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/, 'pseudo-class': { - pattern: /:[-\w]+((\([^\(]*\([^\)]*\)[^\)]*\))|(\(.*?\)))?/, + pattern: /:[-\w]+(?:(?:\([^\(]*\([^\)]*\)[^\)]*\))|(?:\(.*?\)))?/, greedy: true, inside: { 'n-th': [ @@ -32,7 +32,7 @@ 'id': /#[-:.\w]+/, 'tag': /[-\w]+/, 'selector-list': /,/, - 'combinator': />|\+|~|(\|\|)]/, + 'combinator': />|\+|~|(?:\|\|)]/, 'attribute': { pattern: RegExp('\\[(?:[^[\\]"\']|' + string.source + ')*\\]'), greedy: true, diff --git a/components/prism-css-extras.min.js b/components/prism-css-extras.min.js index cccd1443b6..0df44c33a9 100644 --- a/components/prism-css-extras.min.js +++ b/components/prism-css-extras.min.js @@ -1 +1 @@ -!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;for(var r in e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":{pattern:/:[-\w]+((\([^\(]*\([^\)]*\)[^\)]*\))|(\(.*?\)))?/,greedy:!0,inside:{"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],punctuation:/[()]/}},class:/\.[-:.\w]+/,id:/#[-:.\w]+/,tag:/[-\w]+/,"selector-list":/,/,combinator:/>|\+|~|(\|\|)]/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}}}},a)"pseudo-class"!==r&&"tag"!==r&&(a["pseudo-class"].inside[r]=a[r]);e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var i={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},t={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:i,number:t,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:i,number:t})}(Prism); \ No newline at end of file +!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;for(var r in e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":{pattern:/:[-\w]+(?:(?:\([^\(]*\([^\)]*\)[^\)]*\))|(?:\(.*?\)))?/,greedy:!0,inside:{"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],punctuation:/[()]/}},class:/\.[-:.\w]+/,id:/#[-:.\w]+/,tag:/[-\w]+/,"selector-list":/,/,combinator:/>|\+|~|(?:\|\|)]/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}}}},a)"pseudo-class"!==r&&"tag"!==r&&(a["pseudo-class"].inside[r]=a[r]);e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var i={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},t={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:i,number:t,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:i,number:t})}(Prism); \ No newline at end of file From 4848fda7136818e3a2b73c7b2369302bdd358dd0 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: Fri, 8 May 2020 20:43:34 +0800 Subject: [PATCH 10/12] CSS Extra: restore `pseudo-class` tokenize, put the `combinator` and `tag` behind the `n-th` token to avoid problem. --- components/prism-css-extras.js | 49 ++++----- components/prism-css-extras.min.js | 2 +- .../css!+css-extras/selector_feature.test | 4 +- .../selector_n-th_feature.test | 100 ++++++++---------- .../selector_pseudo-class_feature.test | 56 +++++----- 5 files changed, 90 insertions(+), 121 deletions(-) diff --git a/components/prism-css-extras.js b/components/prism-css-extras.js index 6c035d0814..16998b56a7 100644 --- a/components/prism-css-extras.js +++ b/components/prism-css-extras.js @@ -7,32 +7,9 @@ pattern: Prism.languages.css.selector, inside: selectorInside = { 'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/, - 'pseudo-class': { - pattern: /:[-\w]+(?:(?:\([^\(]*\([^\)]*\)[^\)]*\))|(?:\(.*?\)))?/, - greedy: true, - inside: { - 'n-th': [ - { - pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/, - lookbehind: true, - inside: { - 'number': /[\dn]+/, - 'operator': /[+-]/ - } - }, - { - pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i, - lookbehind: true - } - ], - 'punctuation': /[()]/, - } - }, + 'pseudo-class': /:[-\w]+/, 'class': /\.[-:.\w]+/, 'id': /#[-:.\w]+/, - 'tag': /[-\w]+/, - 'selector-list': /,/, - 'combinator': />|\+|~|(?:\|\|)]/, 'attribute': { pattern: RegExp('\\[(?:[^[\\]"\']|' + string.source + ')*\\]'), greedy: true, @@ -64,16 +41,26 @@ 'operator': /[|~*^$]?=/ } }, + 'n-th': [ + { + pattern: /(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/, + lookbehind: true, + inside: { + 'number': /[\dn]+/, + 'operator': /[+-]/ + } + }, + { + pattern: /(\(\s*)(?:even|odd)(?=\s*\))/i, + lookbehind: true + } + ], + 'combinator': />|\+|~|(?:\|\|)]/, + 'tag': /[a-zA-Z][-\w]*/, + 'punctuation': /[(),]/, } }; - // TODO: support 'pseudo-class' and 'tag' token - for (var token in selectorInside) { - if (token !== 'pseudo-class' && token !== 'tag') { - selectorInside['pseudo-class'].inside[token] = selectorInside[token]; - } - } - Prism.languages.css['atrule'].inside['selector-function-argument'].inside = selectorInside; Prism.languages.insertBefore('css', 'property', { diff --git a/components/prism-css-extras.min.js b/components/prism-css-extras.min.js index 0df44c33a9..eec4c1bacb 100644 --- a/components/prism-css-extras.min.js +++ b/components/prism-css-extras.min.js @@ -1 +1 @@ -!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;for(var r in e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":{pattern:/:[-\w]+(?:(?:\([^\(]*\([^\)]*\)[^\)]*\))|(?:\(.*?\)))?/,greedy:!0,inside:{"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],punctuation:/[()]/}},class:/\.[-:.\w]+/,id:/#[-:.\w]+/,tag:/[-\w]+/,"selector-list":/,/,combinator:/>|\+|~|(?:\|\|)]/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}}}},a)"pseudo-class"!==r&&"tag"!==r&&(a["pseudo-class"].inside[r]=a[r]);e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var i={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},t={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:i,number:t,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:i,number:t})}(Prism); \ No newline at end of file +!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],combinator:/>|\+|~|(?:\|\|)]/,tag:/[a-zA-Z][-\w]*/,punctuation:/[(),]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var r={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},i={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:r,number:i,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:i})}(Prism); \ No newline at end of file diff --git a/tests/languages/css!+css-extras/selector_feature.test b/tests/languages/css!+css-extras/selector_feature.test index e81057427a..c55065717d 100644 --- a/tests/languages/css!+css-extras/selector_feature.test +++ b/tests/languages/css!+css-extras/selector_feature.test @@ -37,13 +37,13 @@ div { ["id", "#foo"], ["combinator", ">"], ["class", ".bar"], - ["pseudo-class", [":hover"]], + ["pseudo-class", ":hover"], ["pseudo-element", ":after"] ]], ["punctuation", "{"], ["selector", [ ["tag", "span"], - ["selector-list", ","], + ["punctuation", ","], ["tag", "div"] ]], ["punctuation", "{"] ] diff --git a/tests/languages/css!+css-extras/selector_n-th_feature.test b/tests/languages/css!+css-extras/selector_n-th_feature.test index 0c27de2ef1..0b7bcb8e9a 100644 --- a/tests/languages/css!+css-extras/selector_n-th_feature.test +++ b/tests/languages/css!+css-extras/selector_n-th_feature.test @@ -9,82 +9,70 @@ [ ["selector", [ - ["pseudo-class", [ - ":nth-child", - ["punctuation", "("], - ["n-th", [ - ["number", "2n"], - ["operator", "+"], - ["number", "1"] - ]], - ["punctuation", ")"] - ] - ]]], - ["punctuation", "{"], - ["punctuation", "}"], - - ["selector", [ - ["pseudo-class", [ - ":nth-child", - ["punctuation", "("], + ["pseudo-class", ":nth-child"], + ["punctuation", "("], ["n-th", [ - ["operator", "+"], ["number", "2n"], - ["operator", "-"], + ["operator", "+"], ["number", "1"] ]], - ["punctuation", ")"] - ] - ]]], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"], ["selector", [ - ["pseudo-class", [ - ":nth-child", - ["punctuation", "("], - ["n-th", [ - ["number", "2n"] - ]], - ["punctuation", ")"] - ] - ]]], + ["pseudo-class", ":nth-child"], + ["punctuation", "("], + ["n-th", [ + ["operator", "+"], + ["number", "2n"], + ["operator", "-"], + ["number", "1"] + ]], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"], ["selector", [ - ["pseudo-class", [ - ":nth-child", - ["punctuation", "("], - ["n-th", [ - ["operator", "+"], - ["number", "5"] - ]], - ["punctuation", ")"] - ] - ]]], + ["pseudo-class", ":nth-child"], + ["punctuation", "("], + ["n-th", [ + ["number", "2n"] + ]], + ["punctuation", ")"] + ]], + ["punctuation", "{"], + ["punctuation", "}"], + + ["selector", [ + ["pseudo-class", ":nth-child"], + ["punctuation", "("], + ["n-th", [ + ["operator", "+"], + ["number", "5"] + ]], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"], ["selector", [ - ["pseudo-class", [ - ":nth-child", - ["punctuation", "("], - ["n-th", "even"], - ["punctuation", ")"] - ] - ]]], + ["pseudo-class", ":nth-child"], + ["punctuation", "("], + ["n-th", "even"], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"], ["selector", [ - ["pseudo-class", [ - ":nth-child", - ["punctuation", "("], - ["n-th", "odd"], - ["punctuation", ")"] - ] - ]]], + ["pseudo-class", ":nth-child"], + ["punctuation", "("], + ["n-th", "odd"], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"] ] diff --git a/tests/languages/css!+css-extras/selector_pseudo-class_feature.test b/tests/languages/css!+css-extras/selector_pseudo-class_feature.test index 6fd260cab6..92898c50ce 100644 --- a/tests/languages/css!+css-extras/selector_pseudo-class_feature.test +++ b/tests/languages/css!+css-extras/selector_pseudo-class_feature.test @@ -11,51 +11,45 @@ foo:hover {} [ ["selector", [ ["tag", "foo"], - ["pseudo-class", [":hover"]] + ["pseudo-class", ":hover"] ]], ["punctuation", "{"], ["punctuation", "}"], ["selector", [ - ["pseudo-class", [ - ":lang", - ["punctuation", "("], - "en", - ["punctuation", ")"] - ] - ]]], + ["pseudo-class", ":lang"], + ["punctuation", "("], + ["tag", "en"], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"], ["selector", [ ["class", ".bar"], - ["pseudo-class", [ - ":not", - ["punctuation", "("], - "baz:hover", - ["punctuation", ")"] - ]], - ["pseudo-class", [ - ":not", - ["punctuation", "("], - ["class", ".foo"], - ["punctuation", ")"] - ] - ]]], + ["pseudo-class", ":not"], + ["punctuation", "("], + ["tag", "baz"], + ["pseudo-class", ":hover"], + ["punctuation", ")"], + ["pseudo-class", ":not"], + ["punctuation", "("], + ["class", ".foo"], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"], ["selector", [ - ["pseudo-class", [ - ":where", - ["punctuation", "("], - "p:not", - ["punctuation", "("], - ["class", ".class"], - ["punctuation", ")"], - ["punctuation", ")"] - ] - ]]], + ["pseudo-class", ":where"], + ["punctuation", "("], + ["tag", "p"], + ["pseudo-class", ":not"], + ["punctuation", "("], + ["class", ".class"], + ["punctuation", ")"], + ["punctuation", ")"] + ]], ["punctuation", "{"], ["punctuation", "}"] ] From c500ca3474f1c8bbbf12f13e35978660f51ef523 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: Fri, 8 May 2020 21:47:49 +0800 Subject: [PATCH 11/12] CSS Extra: rewrite the `combinator` regex and add relative tests to test every character. --- components/prism-css-extras.js | 2 +- components/prism-css-extras.min.js | 2 +- .../css!+css-extras/selector_feature.test | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/components/prism-css-extras.js b/components/prism-css-extras.js index 16998b56a7..571d6cfaa5 100644 --- a/components/prism-css-extras.js +++ b/components/prism-css-extras.js @@ -55,7 +55,7 @@ lookbehind: true } ], - 'combinator': />|\+|~|(?:\|\|)]/, + 'combinator': />|\+|~|\|\|/, 'tag': /[a-zA-Z][-\w]*/, 'punctuation': /[(),]/, } diff --git a/components/prism-css-extras.min.js b/components/prism-css-extras.min.js index eec4c1bacb..eebf83c1a4 100644 --- a/components/prism-css-extras.min.js +++ b/components/prism-css-extras.min.js @@ -1 +1 @@ -!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],combinator:/>|\+|~|(?:\|\|)]/,tag:/[a-zA-Z][-\w]*/,punctuation:/[(),]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var r={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},i={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:r,number:i,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:i})}(Prism); \ No newline at end of file +!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],combinator:/>|\+|~|\|\|/,tag:/[a-zA-Z][-\w]*/,punctuation:/[(),]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var r={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},i={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:r,number:i,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:i})}(Prism); \ No newline at end of file diff --git a/tests/languages/css!+css-extras/selector_feature.test b/tests/languages/css!+css-extras/selector_feature.test index c55065717d..f46ca4cef5 100644 --- a/tests/languages/css!+css-extras/selector_feature.test +++ b/tests/languages/css!+css-extras/selector_feature.test @@ -10,6 +10,11 @@ foo#bar { span, div { +div > p, +.css-li ~ .css-li, +.previous-selector + .selector, +.selected || td { + ---------------------------------------------------- [ @@ -45,6 +50,24 @@ div { ["tag", "span"], ["punctuation", ","], ["tag", "div"] + ]], ["punctuation", "{"], + + ["selector", [ + ["tag", "div"], + ["combinator", ">"], + ["tag", "p"], + ["punctuation", ","], + ["class", ".css-li"], + ["combinator", "~"], + ["class", ".css-li"], + ["punctuation", ","], + ["class", ".previous-selector"], + ["combinator", "+"], + ["class", ".selector"], + ["punctuation", ","], + ["class", ".selected"], + ["combinator", "||"], + ["tag", "td"] ]], ["punctuation", "{"] ] From 61920bc49e42844fdc2e9698db1c72bdb1277721 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: Sat, 9 May 2020 01:30:13 +0800 Subject: [PATCH 12/12] CSS Extra: remove `tag` token but left comment describing this history --- components/prism-css-extras.js | 6 +++++- components/prism-css-extras.min.js | 2 +- .../css!+css-extras/number_feature.test | 2 +- .../css!+css-extras/selector_feature.test | 18 +++++++++--------- .../selector_pseudo-class_feature.test | 8 ++++---- .../css!+css-extras/variable_feature.test | 2 +- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/prism-css-extras.js b/components/prism-css-extras.js index 571d6cfaa5..f62c47bbd2 100644 --- a/components/prism-css-extras.js +++ b/components/prism-css-extras.js @@ -56,7 +56,11 @@ } ], 'combinator': />|\+|~|\|\|/, - 'tag': /[a-zA-Z][-\w]*/, + + // the `tag` token has been existed and removed. + // because we can't find a perfect tokenize to match it. + // if you want to add it, please read https://github.com/PrismJS/prism/pull/2373 first. + 'punctuation': /[(),]/, } }; diff --git a/components/prism-css-extras.min.js b/components/prism-css-extras.min.js index eebf83c1a4..81ee713413 100644 --- a/components/prism-css-extras.min.js +++ b/components/prism-css-extras.min.js @@ -1 +1 @@ -!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],combinator:/>|\+|~|\|\|/,tag:/[a-zA-Z][-\w]*/,punctuation:/[(),]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var r={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},i={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:r,number:i,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:i})}(Prism); \ No newline at end of file +!function(e){var a,n=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;e.languages.css.selector={pattern:e.languages.css.selector,inside:a={"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:RegExp("\\[(?:[^[\\]\"']|"+n.source+")*\\]"),greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},"attr-name":{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},"attr-value":[n,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],combinator:/>|\+|~|\|\|/,punctuation:/[(),]/}},e.languages.css.atrule.inside["selector-function-argument"].inside=a,e.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}});var r={pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},i={pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0};e.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:{pattern:/\B#(?:[\da-f]{1,2}){3,4}\b/i,alias:"color"},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:r,number:i,function:/[\w-]+(?=\()/,punctuation:/[(),]/}}],entity:/\\[\da-f]{1,8}/i,unit:r,number:i})}(Prism); \ No newline at end of file diff --git a/tests/languages/css!+css-extras/number_feature.test b/tests/languages/css!+css-extras/number_feature.test index 6e71d4b5ae..1ac34b99ca 100644 --- a/tests/languages/css!+css-extras/number_feature.test +++ b/tests/languages/css!+css-extras/number_feature.test @@ -24,7 +24,7 @@ foo { ["comment", "/* complex example */"], ["selector", [ - ["tag", "foo"] + "foo" ]], ["punctuation", "{"], diff --git a/tests/languages/css!+css-extras/selector_feature.test b/tests/languages/css!+css-extras/selector_feature.test index f46ca4cef5..ddd6961403 100644 --- a/tests/languages/css!+css-extras/selector_feature.test +++ b/tests/languages/css!+css-extras/selector_feature.test @@ -19,22 +19,22 @@ div > p, [ ["selector", [ - ["tag", "foo"], + "foo", ["pseudo-element", ":after"] ]], ["punctuation", "{"], ["selector", [ - ["tag", "foo"], + "foo", ["pseudo-element", "::first-letter"] ]], ["punctuation", "{"], ["selector", [ - ["tag", "foo"], + "foo", ["class", ".bar"] ]], ["punctuation", "{"], ["selector", [ - ["tag", "foo"], + "foo", ["id", "#bar"] ]], ["punctuation", "{"], @@ -47,15 +47,15 @@ div > p, ]], ["punctuation", "{"], ["selector", [ - ["tag", "span"], + "span", ["punctuation", ","], - ["tag", "div"] + "\r\ndiv" ]], ["punctuation", "{"], ["selector", [ - ["tag", "div"], + "div ", ["combinator", ">"], - ["tag", "p"], + " p", ["punctuation", ","], ["class", ".css-li"], ["combinator", "~"], @@ -67,7 +67,7 @@ div > p, ["punctuation", ","], ["class", ".selected"], ["combinator", "||"], - ["tag", "td"] + " td" ]], ["punctuation", "{"] ] diff --git a/tests/languages/css!+css-extras/selector_pseudo-class_feature.test b/tests/languages/css!+css-extras/selector_pseudo-class_feature.test index 92898c50ce..bf2cea6217 100644 --- a/tests/languages/css!+css-extras/selector_pseudo-class_feature.test +++ b/tests/languages/css!+css-extras/selector_pseudo-class_feature.test @@ -10,7 +10,7 @@ foo:hover {} [ ["selector", [ - ["tag", "foo"], + "foo", ["pseudo-class", ":hover"] ]], ["punctuation", "{"], @@ -19,7 +19,7 @@ foo:hover {} ["selector", [ ["pseudo-class", ":lang"], ["punctuation", "("], - ["tag", "en"], + "en", ["punctuation", ")"] ]], ["punctuation", "{"], @@ -29,7 +29,7 @@ foo:hover {} ["class", ".bar"], ["pseudo-class", ":not"], ["punctuation", "("], - ["tag", "baz"], + "baz", ["pseudo-class", ":hover"], ["punctuation", ")"], ["pseudo-class", ":not"], @@ -43,7 +43,7 @@ foo:hover {} ["selector", [ ["pseudo-class", ":where"], ["punctuation", "("], - ["tag", "p"], + "p", ["pseudo-class", ":not"], ["punctuation", "("], ["class", ".class"], diff --git a/tests/languages/css!+css-extras/variable_feature.test b/tests/languages/css!+css-extras/variable_feature.test index 5f673573de..657688fcd1 100644 --- a/tests/languages/css!+css-extras/variable_feature.test +++ b/tests/languages/css!+css-extras/variable_feature.test @@ -10,7 +10,7 @@ calc(100% - var(--margin-size) * 2) ---------------------------------------------------- [ - ["selector", [["tag", "element"]]], + ["selector", ["element"]], ["punctuation", "{"], ["variable", "--foo"], ["punctuation", ":"],