Skip to content

Commit

Permalink
CSS: Improved url and added keywords (#2432)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Jun 27, 2020
1 parent 22eb5ca commit 964de5a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
13 changes: 11 additions & 2 deletions components/prism-css.js
Expand Up @@ -12,16 +12,25 @@
pattern: /(\bselector\s*\((?!\s*\))\s*)(?:[^()]|\((?:[^()]|\([^()]*\))*\))+?(?=\s*\))/,
lookbehind: true,
alias: 'selector'
},
'keyword': {
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
lookbehind: true
}
// See rest below
}
},
'url': {
pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
// https://drafts.csswg.org/css-values-3/#urls
pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
greedy: true,
inside: {
'function': /^url/i,
'punctuation': /^\(|\)$/
'punctuation': /^\(|\)$/,
'string': {
pattern: RegExp('^' + string.source + '$'),
alias: 'url'
}
}
},
'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
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.

13 changes: 11 additions & 2 deletions prism.js
Expand Up @@ -1329,16 +1329,25 @@ Prism.languages.rss = Prism.languages.xml;
pattern: /(\bselector\s*\((?!\s*\))\s*)(?:[^()]|\((?:[^()]|\([^()]*\))*\))+?(?=\s*\))/,
lookbehind: true,
alias: 'selector'
},
'keyword': {
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
lookbehind: true
}
// See rest below
}
},
'url': {
pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
// https://drafts.csswg.org/css-values-3/#urls
pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
greedy: true,
inside: {
'function': /^url/i,
'punctuation': /^\(|\)$/
'punctuation': /^\(|\)$/,
'string': {
pattern: RegExp('^' + string.source + '$'),
alias: 'url'
}
}
},
'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
Expand Down
4 changes: 2 additions & 2 deletions tests/languages/css/atrule_feature.test
Expand Up @@ -31,7 +31,7 @@
["punctuation", ":"],
" 640px",
["punctuation", ")"],
" and ",
["keyword", "and"],
["punctuation", "("],
["property", "min-height"],
["punctuation", ":"],
Expand All @@ -47,7 +47,7 @@
["punctuation", ":"],
" 50vmax",
["punctuation", ")"],
"\r\n\tor ",
["keyword", "or"],
["punctuation", "("],
["property", "top"],
["punctuation", ":"],
Expand Down
19 changes: 13 additions & 6 deletions tests/languages/css/url_feature.test
@@ -1,4 +1,5 @@
url(foo.png)
url(close\)parens)
url('foo.png')
url("foo.png")
url('foo\
Expand All @@ -21,33 +22,39 @@ bar.png")
["url", [
["function", "url"],
["punctuation", "("],
"'foo.png'",
"close\\)parens",
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
"\"foo.png\"",
["string", "'foo.png'"],
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
"'foo\\\r\nbar.png'",
["string", "\"foo.png\""],
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
"\"foo\\\r\nbar.png\"",
["string", "'foo\\\r\nbar.png'"],
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
["string", "\"foo\\\r\nbar.png\""],
["punctuation", ")"]
]],
["atrule", [
["rule", "@import"],
["url", [
["function", "url"],
["punctuation", "("],
"\"https://cdn.jsdelivr.net/npm/prismj1.19.0/themes/prism-dark.css\"",
["string", "\"https://cdn.jsdelivr.net/npm/prismj1.19.0/themes/prism-dark.css\""],
["punctuation", ")"]
]],
["punctuation", ";"]
Expand All @@ -57,7 +64,7 @@ bar.png")
["url", [
["function", "url"],
["punctuation", "("],
"\"https://cdn.jsdelivr.net/npm/prismjs/themes/prism-dark.css\"",
["string", "\"https://cdn.jsdelivr.net/npm/prismjs/themes/prism-dark.css\""],
["punctuation", ")"]
]],
["punctuation", ";"]
Expand Down

0 comments on commit 964de5a

Please sign in to comment.