Skip to content

Commit

Permalink
CSS: Extended url inside (#1874)
Browse files Browse the repository at this point in the history
This extends the highlighting of the CSS `url` pattern adding highlighting for punctuation and the `url` function.
  • Loading branch information
RunDevelopment authored May 15, 2019
1 parent 5e5a3e0 commit f0a1066
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
8 changes: 7 additions & 1 deletion components/prism-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
// See rest below
}
},
'url': RegExp('url\\((?:' + string.source + '|.*?)\\)', 'i'),
'url': {
pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
inside: {
'function': /^url/i,
'punctuation': /^\(|\)$/
}
},
'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
'string': {
pattern: string,
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.

8 changes: 7 additions & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,13 @@ Prism.languages.svg = Prism.languages.markup;
// See rest below
}
},
'url': RegExp('url\\((?:' + string.source + '|.*?)\\)', 'i'),
'url': {
pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'),
inside: {
'function': /^url/i,
'punctuation': /^\(|\)$/
}
},
'selector': RegExp('[^{}\\s](?:[^{};"\']|' + string.source + ')*?(?=\\s*\\{)'),
'string': {
pattern: string,
Expand Down
9 changes: 7 additions & 2 deletions tests/languages/css/atrule_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
[
["atrule", [
["rule", "@import"],
["url", "url(foo.css)"],
["url", [
["function", "url"],
["punctuation", "("],
"foo.css",
["punctuation", ")"]
]],
["punctuation", ";"]
]],
["atrule", [
Expand Down Expand Up @@ -62,4 +67,4 @@
----------------------------------------------------

Checks for at-rules.
Also checks for LESS variables.
Also checks for LESS variables.
37 changes: 31 additions & 6 deletions tests/languages/css/url_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,38 @@ bar.png")
----------------------------------------------------

[
["url", "url(foo.png)"],
["url", "url('foo.png')"],
["url", "url(\"foo.png\")"],
["url", "url('foo\\\r\nbar.png')"],
["url", "url(\"foo\\\r\nbar.png\")"]
["url", [
["function", "url"],
["punctuation", "("],
"foo.png",
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
"'foo.png'",
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
"\"foo.png\"",
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
"'foo\\\r\nbar.png'",
["punctuation", ")"]
]],
["url", [
["function", "url"],
["punctuation", "("],
"\"foo\\\r\nbar.png\"",
["punctuation", ")"]
]]
]

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

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

0 comments on commit f0a1066

Please sign in to comment.