Skip to content

Commit f0a1066

Browse files
CSS: Extended url inside (#1874)
This extends the highlighting of the CSS `url` pattern adding highlighting for punctuation and the `url` function.
1 parent 5e5a3e0 commit f0a1066

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

components/prism-css.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
// See rest below
1212
}
1313
},
14-
'url': RegExp('url\\((?:' + string.source + '|.*?)\\)', 'i'),
14+
'url': {
15+
pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
16+
inside: {
17+
'function': /^url/i,
18+
'punctuation': /^\(|\)$/
19+
}
20+
},
1521
'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
1622
'string': {
1723
pattern: string,

components/prism-css.min.js

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

prism.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,13 @@ Prism.languages.svg = Prism.languages.markup;
679679
// See rest below
680680
}
681681
},
682-
'url': RegExp('url\\((?:' + string.source + '|.*?)\\)', 'i'),
682+
'url': {
683+
pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
684+
inside: {
685+
'function': /^url/i,
686+
'punctuation': /^\(|\)$/
687+
}
688+
},
683689
'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
684690
'string': {
685691
pattern: string,

tests/languages/css/atrule_feature.test

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
[
1111
["atrule", [
1212
["rule", "@import"],
13-
["url", "url(foo.css)"],
13+
["url", [
14+
["function", "url"],
15+
["punctuation", "("],
16+
"foo.css",
17+
["punctuation", ")"]
18+
]],
1419
["punctuation", ";"]
1520
]],
1621
["atrule", [
@@ -62,4 +67,4 @@
6267
----------------------------------------------------
6368

6469
Checks for at-rules.
65-
Also checks for LESS variables.
70+
Also checks for LESS variables.

tests/languages/css/url_feature.test

+31-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,38 @@ bar.png")
99
----------------------------------------------------
1010

1111
[
12-
["url", "url(foo.png)"],
13-
["url", "url('foo.png')"],
14-
["url", "url(\"foo.png\")"],
15-
["url", "url('foo\\\r\nbar.png')"],
16-
["url", "url(\"foo\\\r\nbar.png\")"]
12+
["url", [
13+
["function", "url"],
14+
["punctuation", "("],
15+
"foo.png",
16+
["punctuation", ")"]
17+
]],
18+
["url", [
19+
["function", "url"],
20+
["punctuation", "("],
21+
"'foo.png'",
22+
["punctuation", ")"]
23+
]],
24+
["url", [
25+
["function", "url"],
26+
["punctuation", "("],
27+
"\"foo.png\"",
28+
["punctuation", ")"]
29+
]],
30+
["url", [
31+
["function", "url"],
32+
["punctuation", "("],
33+
"'foo\\\r\nbar.png'",
34+
["punctuation", ")"]
35+
]],
36+
["url", [
37+
["function", "url"],
38+
["punctuation", "("],
39+
"\"foo\\\r\nbar.png\"",
40+
["punctuation", ")"]
41+
]]
1742
]
1843

1944
----------------------------------------------------
2045

21-
Checks for url(), unquoted, single-quoted and double-quoted.
46+
Checks for url(), unquoted, single-quoted and double-quoted.

0 commit comments

Comments
 (0)