diff --git a/components/prism-css.js b/components/prism-css.js index d236f31659..4d7e718fdc 100644 --- a/components/prism-css.js +++ b/components/prism-css.js @@ -18,6 +18,7 @@ }, 'url': { pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'), + greedy: true, inside: { 'function': /^url/i, 'punctuation': /^\(|\)$/ diff --git a/components/prism-css.min.js b/components/prism-css.min.js index 1f015cac26..c1a74079d1 100644 --- a/components/prism-css.min.js +++ b/components/prism-css.min.js @@ -1 +1 @@ -!function(s){var e=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;s.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-]+[\s\S]*?(?:;|(?=\s*\{))/,inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\((?!\s*\))\s*)(?:[^()]|\((?:[^()]|\([^()]*\))*\))+?(?=\s*\))/,lookbehind:!0,alias:"selector"}}},url:{pattern:RegExp("url\\((?:"+e.source+"|[^\n\r()]*)\\)","i"),inside:{function:/^url/i,punctuation:/^\(|\)$/}},selector:RegExp("[^{}\\s](?:[^{};\"']|"+e.source+")*?(?=\\s*\\{)"),string:{pattern:e,greedy:!0},property:/[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,important:/!important\b/i,function:/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:,]/},s.languages.css.atrule.inside.rest=s.languages.css;var t=s.languages.markup;t&&(t.tag.addInlined("style","css"),s.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:t.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:s.languages.css}},alias:"language-css"}},t.tag))}(Prism); \ No newline at end of file +!function(s){var e=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;s.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-]+[\s\S]*?(?:;|(?=\s*\{))/,inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\((?!\s*\))\s*)(?:[^()]|\((?:[^()]|\([^()]*\))*\))+?(?=\s*\))/,lookbehind:!0,alias:"selector"}}},url:{pattern:RegExp("url\\((?:"+e.source+"|[^\n\r()]*)\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/}},selector:RegExp("[^{}\\s](?:[^{};\"']|"+e.source+")*?(?=\\s*\\{)"),string:{pattern:e,greedy:!0},property:/[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,important:/!important\b/i,function:/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:,]/},s.languages.css.atrule.inside.rest=s.languages.css;var t=s.languages.markup;t&&(t.tag.addInlined("style","css"),s.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:t.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:s.languages.css}},alias:"language-css"}},t.tag))}(Prism); \ No newline at end of file diff --git a/prism.js b/prism.js index 810031392c..5102efcdb1 100644 --- a/prism.js +++ b/prism.js @@ -863,6 +863,7 @@ Prism.languages.svg = Prism.languages.markup; }, 'url': { pattern: RegExp('url\\((?:' + string.source + '|[^\n\r()]*)\\)', 'i'), + greedy: true, inside: { 'function': /^url/i, 'punctuation': /^\(|\)$/ diff --git a/tests/languages/css/url_feature.test b/tests/languages/css/url_feature.test index 690ec4a707..014404b2bc 100644 --- a/tests/languages/css/url_feature.test +++ b/tests/languages/css/url_feature.test @@ -6,6 +6,9 @@ bar.png') url("foo\ bar.png") +@import url("https://cdn.jsdelivr.net/npm/prismj1.19.0/themes/prism-dark.css"); +@import url("https://cdn.jsdelivr.net/npm/prismjs/themes/prism-dark.css"); + ---------------------------------------------------- [ @@ -38,6 +41,26 @@ bar.png") ["punctuation", "("], "\"foo\\\r\nbar.png\"", ["punctuation", ")"] + ]], + ["atrule", [ + ["rule", "@import"], + ["url", [ + ["function", "url"], + ["punctuation", "("], + "\"https://cdn.jsdelivr.net/npm/prismj1.19.0/themes/prism-dark.css\"", + ["punctuation", ")"] + ]], + ["punctuation", ";"] + ]], + ["atrule", [ + ["rule", "@import"], + ["url", [ + ["function", "url"], + ["punctuation", "("], + "\"https://cdn.jsdelivr.net/npm/prismjs/themes/prism-dark.css\"", + ["punctuation", ")"] + ]], + ["punctuation", ";"] ]] ]