Skip to content

Commit

Permalink
CSS Extras & PHP: Fixed too greedy number token (#2009)
Browse files Browse the repository at this point in the history
This fixes the too greedy number tokenization of CSS Extras which cause the placeholders of PHP (via markup templating) to be partly tokenized.

The CSS extras number pattern was adjusted to solve the issue.
  • Loading branch information
RunDevelopment committed Aug 17, 2019
1 parent e2b99f4 commit ebe363f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
6 changes: 5 additions & 1 deletion components/prism-css-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
2 changes: 1 addition & 1 deletion components/prism-css-extras.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 53 additions & 2 deletions tests/languages/css!+css-extras/number_feature.test
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@
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);
}

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

[
["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", "}"]
]

----------------------------------------------------
Expand Down
44 changes: 44 additions & 0 deletions tests/languages/php!+css-extras/issue2008.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<img style="width:<?php echo (80 / count($images)) ?>%"/>

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

[
["tag", [
["tag", [
["punctuation", "<"],
"img"
]],
["style-attr", [
["attr-name", [
["attr-name", [
"style"
]]
]],
["punctuation", "=\""],
["attr-value", [
["property", "width"],
["punctuation", ":"],
["php", [
["delimiter", "<?php"],
["keyword", "echo"],
["punctuation", "("],
["number", "80"],
["operator", "/"],
["function", "count"],
["punctuation", "("],
["variable", "$images"],
["punctuation", ")"],
["punctuation", ")"],
["delimiter", "?>"]
]],
"%"
]],
["punctuation", "\""]
]],
["punctuation", "/>"]
]]
]

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

Checks for #2008 where a part of markup templating's placeholder was tokenized as `number` by CSS Extras.

0 comments on commit ebe363f

Please sign in to comment.