Identifying !important correctly
- Dominant language
- PHP
- Stars
- 6
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Great class thank you for cleaning up the original class as it really didn't work especially for `@media` queries. :)
I tried some CSS that contained the following:
```
h1 {
font-size: 5.3em!important;
font-size: 3.3em;
}
```
However, on this line: https://github.com/fahad19/li3_css/blob/master/config/css_parser.php#L466 - `in_array` is being used which will not correctly identify that the important exists and browsers will accept that use of important: Also the following fails to be identified even though the browsers will accept them i.e. `! important` - when spaces exist.
So I changed that line to this:
`if (!$this->substr_in_array('important', $tokens) && !$this->substr_in_array('!', $tokens)) {`
Using the below function:
```
/**
*
* @Search for substring in an array
* @param string $neele
* @param mixed $haystack
* @return bool
*
*/
function substr_in_array($needle, $haystack) {
$needle = (array) $needle;
$needle = array_map('preg_quote', $needle);
foreach ($needle as $pattern) {
if (count(preg_grep("/$pattern/", $haystack)) > 0)
return true;
}
return false;
}
```
I think this is more resilient, what do you think?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.