Skip to content

Commit 0d4b6cb

Browse files
CSS: Fixed @-rules not accounting for strings (#3438)
1 parent 293dce4 commit 0d4b6cb

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

components/prism-css.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Prism.languages.css = {
66
'comment': /\/\*[\s\S]*?\*\//,
77
'atrule': {
8-
pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
8+
pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
99
inside: {
1010
'rule': /^@[\w-]+/,
1111
'selector-function-argument': {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ Prism.languages.rss = Prism.languages.xml;
14681468
Prism.languages.css = {
14691469
'comment': /\/\*[\s\S]*?\*\//,
14701470
'atrule': {
1471-
pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
1471+
pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
14721472
inside: {
14731473
'rule': /^@[\w-]+/,
14741474
'selector-function-argument': {

tests/languages/css/atrule_feature.test

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@supports (top: 50vmax)
55
or (top: 50vw) {}
66
@main-color: red;
7+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
78

89
----------------------------------------------------
910

@@ -18,12 +19,14 @@
1819
]],
1920
["punctuation", ";"]
2021
]],
22+
2123
["atrule", [
2224
["rule", "@media"],
2325
" print"
2426
]],
2527
["punctuation", "{"],
2628
["punctuation", "}"],
29+
2730
["atrule", [
2831
["rule", "@media"],
2932
["punctuation", "("],
@@ -40,13 +43,15 @@
4043
]],
4144
["punctuation", "{"],
4245
["punctuation", "}"],
46+
4347
["atrule", [
4448
["rule", "@supports"],
4549
["punctuation", "("],
4650
["property", "top"],
4751
["punctuation", ":"],
4852
" 50vmax",
4953
["punctuation", ")"],
54+
5055
["keyword", "or"],
5156
["punctuation", "("],
5257
["property", "top"],
@@ -56,11 +61,23 @@
5661
]],
5762
["punctuation", "{"],
5863
["punctuation", "}"],
64+
5965
["atrule", [
6066
["rule", "@main-color"],
6167
["punctuation", ":"],
6268
" red",
6369
["punctuation", ";"]
70+
]],
71+
72+
["atrule", [
73+
["rule", "@import"],
74+
["url", [
75+
["function", "url"],
76+
["punctuation", "("],
77+
["string", "'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap'"],
78+
["punctuation", ")"]
79+
]],
80+
["punctuation", ";"]
6481
]]
6582
]
6683

0 commit comments

Comments
 (0)