diff --git a/components/prism-css-extras.js b/components/prism-css-extras.js index e0c7ef297d..85d280cb3d 100644 --- a/components/prism-css-extras.js +++ b/components/prism-css-extras.js @@ -72,5 +72,9 @@ Prism.languages.insertBefore('css', 'function', { pattern: /(\d)(?:%|[a-z]+)/, lookbehind: true }, - 'number': /-?[\d.]+/ + 'number': { + // 123 -123 .123 -.123 12.3 -12.3 + pattern: /(^|[^\w.-])-?\d*\.?\d+/, + lookbehind: true + } }); diff --git a/components/prism-css-extras.min.js b/components/prism-css-extras.min.js index 0576f5d6f0..079e931f37 100644 --- a/components/prism-css-extras.min.js +++ b/components/prism-css-extras.min.js @@ -1 +1 @@ -Prism.languages.css.selector={pattern:Prism.languages.css.selector,inside:{"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:/\[(?:[^[\]"']|("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1)*\]/,greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},attribute:{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},value:[/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],punctuation:/[()]/}},Prism.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}}),Prism.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:/#[\da-f]{3,8}/i,entity:/\\[\da-f]{1,8}/i,unit:{pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},number:/-?[\d.]+/}); \ No newline at end of file +Prism.languages.css.selector={pattern:Prism.languages.css.selector,inside:{"pseudo-element":/:(?:after|before|first-letter|first-line|selection)|::[-\w]+/,"pseudo-class":/:[-\w]+/,class:/\.[-:.\w]+/,id:/#[-:.\w]+/,attribute:{pattern:/\[(?:[^[\]"']|("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1)*\]/,greedy:!0,inside:{punctuation:/^\[|\]$/,"case-sensitivity":{pattern:/(\s)[si]$/i,lookbehind:!0,alias:"keyword"},namespace:{pattern:/^(\s*)[-*\w\xA0-\uFFFF]*\|(?!=)/,lookbehind:!0,inside:{punctuation:/\|$/}},attribute:{pattern:/^(\s*)[-\w\xA0-\uFFFF]+/,lookbehind:!0},value:[/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,{pattern:/(=\s*)[-\w\xA0-\uFFFF]+(?=\s*$)/,lookbehind:!0}],operator:/[|~*^$]?=/}},"n-th":[{pattern:/(\(\s*)[+-]?\d*[\dn](?:\s*[+-]\s*\d+)?(?=\s*\))/,lookbehind:!0,inside:{number:/[\dn]+/,operator:/[+-]/}},{pattern:/(\(\s*)(?:even|odd)(?=\s*\))/i,lookbehind:!0}],punctuation:/[()]/}},Prism.languages.insertBefore("css","property",{variable:{pattern:/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i,lookbehind:!0}}),Prism.languages.insertBefore("css","function",{operator:{pattern:/(\s)[+\-*\/](?=\s)/,lookbehind:!0},hexcode:/#[\da-f]{3,8}/i,entity:/\\[\da-f]{1,8}/i,unit:{pattern:/(\d)(?:%|[a-z]+)/,lookbehind:!0},number:{pattern:/(^|[^\w.-])-?\d*\.?\d+/,lookbehind:!0}}); \ No newline at end of file diff --git a/tests/languages/css!+css-extras/number_feature.test b/tests/languages/css!+css-extras/number_feature.test index ef58e62036..1ac34b99ca 100644 --- a/tests/languages/css!+css-extras/number_feature.test +++ b/tests/languages/css!+css-extras/number_feature.test @@ -1,7 +1,16 @@ 42 3.14159 -42 --3.14 +-3.14159 +.5 +-.5 + +/* complex example */ +foo { + foo: 0 1em 2ch; + bar:-0px 3px; + baz:calc(100% - 5px - -4em); +} ---------------------------------------------------- @@ -9,7 +18,49 @@ ["number", "42"], ["number", "3.14159"], ["number", "-42"], - ["number", "-3.14"] + ["number", "-3.14159"], + ["number", ".5"], + ["number", "-.5"], + + ["comment", "/* complex example */"], + ["selector", [ + "foo" + ]], + ["punctuation", "{"], + + ["property", "foo"], + ["punctuation", ":"], + ["number", "0"], + ["number", "1"], + ["unit", "em"], + ["number", "2"], + ["unit", "ch"], + ["punctuation", ";"], + + ["property", "bar"], + ["punctuation", ":"], + ["number", "-0"], + ["unit", "px"], + ["number", "3"], + ["unit", "px"], + ["punctuation", ";"], + + ["property", "baz"], + ["punctuation", ":"], + ["function", "calc"], + ["punctuation", "("], + ["number", "100"], + ["unit", "%"], + ["operator", "-"], + ["number", "5"], + ["unit", "px"], + ["operator", "-"], + ["number", "-4"], + ["unit", "em"], + ["punctuation", ")"], + ["punctuation", ";"], + + ["punctuation", "}"] ] ---------------------------------------------------- diff --git a/tests/languages/php!+css-extras/issue2008.test b/tests/languages/php!+css-extras/issue2008.test new file mode 100644 index 0000000000..4710e4ae46 --- /dev/null +++ b/tests/languages/php!+css-extras/issue2008.test @@ -0,0 +1,44 @@ + + +---------------------------------------------------- + +[ + ["tag", [ + ["tag", [ + ["punctuation", "<"], + "img" + ]], + ["style-attr", [ + ["attr-name", [ + ["attr-name", [ + "style" + ]] + ]], + ["punctuation", "=\""], + ["attr-value", [ + ["property", "width"], + ["punctuation", ":"], + ["php", [ + ["delimiter", ""] + ]], + "%" + ]], + ["punctuation", "\""] + ]], + ["punctuation", "/>"] + ]] +] + +---------------------------------------------------- + +Checks for #2008 where a part of markup templating's placeholder was tokenized as `number` by CSS Extras.