Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stylus: Put the comment token behind the string token and set the greedy property to true #2372

Merged
merged 10 commits into from May 7, 2020
Merged
11 changes: 6 additions & 5 deletions components/prism-stylus.js
Expand Up @@ -74,10 +74,6 @@
};

Prism.languages.stylus = {
'comment': {
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
lookbehind: true
},
'atrule-declaration': {
pattern: /(^\s*)@.+/m,
lookbehind: true,
Expand Down Expand Up @@ -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:]+/,
Expand All @@ -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': /[{}()\[\];:.]/
};
Expand Down
2 changes: 1 addition & 1 deletion components/prism-stylus.min.js

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

13 changes: 13 additions & 0 deletions tests/languages/stylus/atrule-declaration_feature.test
Expand Up @@ -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

----------------------------------------------------

Expand All @@ -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"]
]]
]

Expand Down
8 changes: 8 additions & 0 deletions tests/languages/stylus/keyword_feature.test
Expand Up @@ -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

----------------------------------------------------

Expand Down Expand Up @@ -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"]
]]
]

Expand Down
7 changes: 6 additions & 1 deletion tests/languages/stylus/selector_feature.test
Expand Up @@ -18,6 +18,9 @@ color red
{foo} {bar}:hover
color red

div // comment
display inline-block // comment

----------------------------------------------------

[
Expand All @@ -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"]]]
]

----------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions tests/languages/stylus/variable-declaration_feature.test
Expand Up @@ -2,6 +2,7 @@ foo = 'bar'
a = 4
bar-baz = 5
a += 8
url = "http://example.com" // comment

----------------------------------------------------

Expand All @@ -25,6 +26,12 @@ a += 8
["variable", "a"],
["operator", "+="],
["number", "8"]
]],
["variable-declaration", [
["variable", "url"],
["operator", "="],
["string", "\"http://example.com\""],
["comment", "// comment"]
]]
]

Expand Down