Skip to content

Commit 0d65d6c

Browse files
author
那里好脏不可以
authored
Stylus: Fixed comments breaking strings and URLs (#2361)
1 parent 032910b commit 0d65d6c

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

components/prism-stylus.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
(function (Prism) {
22
var inside = {
3-
'url': /url\((["']?).*?\1\)/i,
3+
'comment': {
4+
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
5+
lookbehind: true
6+
},
7+
'url': {
8+
pattern: /url\((["']?).*?\1\)/i,
9+
greedy: true
10+
},
411
'string': {
512
pattern: /("|')(?:(?!\1)[^\\\r\n]|\\(?:\r\n|[\s\S]))*\1/,
613
greedy: true
@@ -78,6 +85,7 @@
7885
'property-declaration': {
7986
pattern: /((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)[^{\r\n]*(?:;|[^{\r\n,](?=$)(?!(?:\r?\n|\r)(?:\{|\2[ \t]+)))/m,
8087
lookbehind: true,
88+
greedy: true,
8189
inside: {
8290
'property': {
8391
pattern: /^[^\s:]+/,

components/prism-stylus.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/stylus/property-declaration_feature.test

+27
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ background-{foo}: bar;
1010
div
1111
{foo} bar
1212

13+
comment
14+
content 'http://www.example.com' // comment
15+
background url(http://example.com) /* comment */
16+
background /* comment */ url("http://example.com")
17+
content '/* this is string not comment */'
18+
1319
----------------------------------------------------
1420

1521
[
@@ -44,6 +50,27 @@ div
4450
]]
4551
]],
4652
" bar"
53+
]],
54+
55+
["selector", ["comment"]],
56+
["property-declaration", [
57+
["property", ["content"]],
58+
["string", "'http://www.example.com'"],
59+
["comment", "// comment"]
60+
]],
61+
["property-declaration", [
62+
["property", ["background"]],
63+
["url", "url(http://example.com)"],
64+
["comment", "/* comment */"]
65+
]],
66+
["property-declaration", [
67+
["property", ["background"]],
68+
["comment", "/* comment */"],
69+
["url", "url(\"http://example.com\")"]
70+
]],
71+
["property-declaration", [
72+
["property", ["content"]],
73+
["string", "'/* this is string not comment */'"]
4774
]]
4875
]
4976

0 commit comments

Comments
 (0)