|
css-sanitizer
Classes to parse and sanitize CSS
|
![Latest Stable Version] ![License]
This library implements a CSS tokenizer, parser and grammar matcher in PHP.
The library follows the following grammar specifications:
The sanitizer recognizes the following CSS modules:
And also,
touch-action property from Pointer Events Level 2, 2019-04-04:dir() pseudo-class from Selectors Level 4, 2022-11-11light-dark() color function from Color Module Level 5, 2024-02-29composer install --prefer-dist composer test
CSS specifications typically contain a summary of value grammars in the property index section. These value grammars map directly to PHP code.
| Syntax | css-sanitizer code |
|---|---|
foo | ‘new KeywordMatcher( 'foo’ )\ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone">foo | bar\ilinebr </td> <td class="markdownTableBodyNone">new KeywordMatcher( [ 'foo', 'bar' ] )\ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"><string>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->string()\ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone"><url>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->url()\ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"><integer>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->integer()\ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone"><number>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->number()\ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"><ratio>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->ratio()\ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone"><percentage>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->percentage()\ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"><length>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->length()\ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone"><frequency>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->frequency()\ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"><angle>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->angle()\ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone"><time>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->time()\ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"><resolution>\ilinebr </td> <td class="markdownTableBodyNone">$matcherFactory->resolution()` |
| Syntax | css-sanitizer code |
|---|---|
a b | new Juxtaposition( [ a, b ] ) |
a && b | UnorderedGroup::allOf( [ a, b ] ) |
a \|\| b | UnorderedGroup::someOf( [ a, b ] ) |
a \| b | new Alternative( [ a, b ] ) |
| Syntax | css-sanitizer code |
|---|---|
a* | Quantifier::star( a ) |
a+ | Quantifier::plus( a ) |
a? | Quantifier::optional( a ) |
a{3,4} | Quantifier::count( a, 3, 4 ) |
a# | Quantifier::hash( a ) |
a! | new NonEmpty( a ) |
This package uses wikimedia/update-history and its conventions.
See https://www.mediawiki.org/wiki/UpdateHistory for details.
We required a CSS sanitizer with several properties:
We could not find a library that fit these requirements, so we created one.
Additional release history is in HISTORY.md.