Skip to content

Commit

Permalink
CSS: Fixed @-rules not accounting for strings (#3438)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Apr 20, 2022
1 parent 293dce4 commit 0d4b6cb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/prism-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Prism.languages.css = {
'comment': /\/\*[\s\S]*?\*\//,
'atrule': {
pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
inside: {
'rule': /^@[\w-]+/,
'selector-function-argument': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-css.min.js

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

2 changes: 1 addition & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ Prism.languages.rss = Prism.languages.xml;
Prism.languages.css = {
'comment': /\/\*[\s\S]*?\*\//,
'atrule': {
pattern: /@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,
pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
inside: {
'rule': /^@[\w-]+/,
'selector-function-argument': {
Expand Down
17 changes: 17 additions & 0 deletions tests/languages/css/atrule_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@supports (top: 50vmax)
or (top: 50vw) {}
@main-color: red;
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

Expand All @@ -18,12 +19,14 @@
]],
["punctuation", ";"]
]],

["atrule", [
["rule", "@media"],
" print"
]],
["punctuation", "{"],
["punctuation", "}"],

["atrule", [
["rule", "@media"],
["punctuation", "("],
Expand All @@ -40,13 +43,15 @@
]],
["punctuation", "{"],
["punctuation", "}"],

["atrule", [
["rule", "@supports"],
["punctuation", "("],
["property", "top"],
["punctuation", ":"],
" 50vmax",
["punctuation", ")"],

["keyword", "or"],
["punctuation", "("],
["property", "top"],
Expand All @@ -56,11 +61,23 @@
]],
["punctuation", "{"],
["punctuation", "}"],

["atrule", [
["rule", "@main-color"],
["punctuation", ":"],
" red",
["punctuation", ";"]
]],

["atrule", [
["rule", "@import"],
["url", [
["function", "url"],
["punctuation", "("],
["string", "'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap'"],
["punctuation", ")"]
]],
["punctuation", ";"]
]]
]

Expand Down

0 comments on commit 0d4b6cb

Please sign in to comment.