Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS: Improved url and added keywords #2432

Merged
merged 1 commit into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions components/prism-css.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -884,16 +884,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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