From 4f6f3c7d49b497bd240b00e13357e63cad95f42b Mon Sep 17 00:00:00 2001 From: Valtteri Laitinen Date: Mon, 24 Dec 2018 17:28:06 +0200 Subject: [PATCH] Allow multiline CSS at-rules (#1676) Allows for CSS at-rules containing line breaks. --- components/prism-css.js | 2 +- components/prism-css.min.js | 2 +- prism.js | 2 +- tests/languages/css/atrule_feature.test | 28 ++++++++++++++++++++----- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/components/prism-css.js b/components/prism-css.js index 284e010682..c19692070c 100644 --- a/components/prism-css.js +++ b/components/prism-css.js @@ -1,7 +1,7 @@ Prism.languages.css = { 'comment': /\/\*[\s\S]*?\*\//, 'atrule': { - pattern: /@[\w-]+?.*?(?:;|(?=\s*\{))/i, + pattern: /@[\w-]+?[\s\S]*?(?:;|(?=\s*\{))/i, inside: { 'rule': /@[\w-]+/ // See rest below diff --git a/components/prism-css.min.js b/components/prism-css.min.js index a4798c615f..8e569afdbd 100644 --- a/components/prism-css.min.js +++ b/components/prism-css.min.js @@ -1 +1 @@ -Prism.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-]+?.*?(?:;|(?=\s*\{))/i,inside:{rule:/@[\w-]+/}},url:/url\((?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,selector:/[^{}\s][^{};]*?(?=\s*\{)/,string:{pattern:/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},property:/[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,important:/!important\b/i,"function":/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:,]/},Prism.languages.css.atrule.inside.rest=Prism.languages.css,Prism.languages.markup&&(Prism.languages.insertBefore("markup","tag",{style:{pattern:/()[\s\S]*?(?=<\/style>)/i,lookbehind:!0,inside:Prism.languages.css,alias:"language-css",greedy:!0}}),Prism.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:Prism.languages.markup.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:Prism.languages.css}},alias:"language-css"}},Prism.languages.markup.tag)); \ No newline at end of file +Prism.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-]+?[\s\S]*?(?:;|(?=\s*\{))/i,inside:{rule:/@[\w-]+/}},url:/url\((?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,selector:/[^{}\s][^{};]*?(?=\s*\{)/,string:{pattern:/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},property:/[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*(?=\s*:)/i,important:/!important\b/i,"function":/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:,]/},Prism.languages.css.atrule.inside.rest=Prism.languages.css,Prism.languages.markup&&(Prism.languages.insertBefore("markup","tag",{style:{pattern:/()[\s\S]*?(?=<\/style>)/i,lookbehind:!0,inside:Prism.languages.css,alias:"language-css",greedy:!0}}),Prism.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|')(?:\\[\s\S]|(?!\1)[^\\])*\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:Prism.languages.markup.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:Prism.languages.css}},alias:"language-css"}},Prism.languages.markup.tag)); \ No newline at end of file diff --git a/prism.js b/prism.js index 0acb158333..4f177d0532 100644 --- a/prism.js +++ b/prism.js @@ -622,7 +622,7 @@ Prism.languages.svg = Prism.languages.markup; Prism.languages.css = { 'comment': /\/\*[\s\S]*?\*\//, 'atrule': { - pattern: /@[\w-]+?.*?(?:;|(?=\s*\{))/i, + pattern: /@[\w-]+?[\s\S]*?(?:;|(?=\s*\{))/i, inside: { 'rule': /@[\w-]+/ // See rest below diff --git a/tests/languages/css/atrule_feature.test b/tests/languages/css/atrule_feature.test index abc75def35..1bc84b0d97 100644 --- a/tests/languages/css/atrule_feature.test +++ b/tests/languages/css/atrule_feature.test @@ -1,6 +1,8 @@ @import url(foo.css); @media print {} @media (min-width: 640px) and (min-height: 1000px) {} +@supports (top: 50vmax) + or (top: 50vw) {} @main-color: red; ---------------------------------------------------- @@ -26,13 +28,29 @@ ["punctuation", ")"], " and ", ["punctuation", "("], - ["property", "min-height"], - ["punctuation", ":"], - " 1000px", - ["punctuation", ")"] + ["property", "min-height"], + ["punctuation", ":"], + " 1000px", + ["punctuation", ")"] ]], ["punctuation", "{"], - ["punctuation", "}"], + ["punctuation", "}"], + ["atrule", [ + ["rule", "@supports"], + ["punctuation", "("], + ["property", "top"], + ["punctuation", ":"], + " 50vmax", + ["punctuation", ")"], + "\r\n\tor ", + ["punctuation", "("], + ["property", "top"], + ["punctuation", ":"], + " 50vw", + ["punctuation", ")"] + ]], + ["punctuation", "{"], + ["punctuation", "}"], ["atrule", [ ["rule", "@main-color"], ["punctuation", ":"],