Skip to content

Commit

Permalink
[FEATURE] Support :only-of-type (#856)
Browse files Browse the repository at this point in the history
Closes #849
  • Loading branch information
JakeQZ authored Apr 1, 2020
1 parent 9a1cba2 commit 86ca17d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## x.y.z

### Added
- Support `:only-of-type` (with a type)
([#849](https://github.com/MyIntervals/emogrifier/issues/849),
[#856](https://github.com/MyIntervals/emogrifier/pull/856))
- Configuration setting methods now all return `$this` to allow chaining
([#824](https://github.com/MyIntervals/emogrifier/pull/824),
[#854](https://github.com/MyIntervals/emogrifier/pull/854))
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ Emogrifier currently supports the following
* [nth-of-type()](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type)
(with a type)
* [only-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-child)
* [only-of-type](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-of-type)
(with a type)

The following selectors are not implemented yet:

Expand All @@ -337,7 +339,6 @@ The following selectors are not implemented yet:
will nonetheless be preserved and copied to a `<style>` element in the
HTML – including (but not necessarily limited to) the following:
* [any-link](https://developer.mozilla.org/en-US/docs/Web/CSS/:any-link)
* [only-of-type](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-of-type)
* [optional](https://developer.mozilla.org/en-US/docs/Web/CSS/:optional)
* [required](https://developer.mozilla.org/en-US/docs/Web/CSS/:required)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"php": "~7.0 || ~7.1 || ~7.2 || ~7.3 || ~7.4",
"ext-dom": "*",
"ext-libxml": "*",
"symfony/css-selector": "^3.4 || ^4.3 || ^5.0"
"symfony/css-selector": "^3.4.32 || ^4.3.5 || ^5.0"
},
"require-dev": {
"grogy/php-parallel-lint": "^1.1.0",
Expand Down
3 changes: 1 addition & 2 deletions src/CssInliner.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class CssInliner extends AbstractHtmlProcessor
*
* @var string
*/
const PSEUDO_CLASS_MATCHER
= 'empty|(?:first|last|nth(?:-last)?+|only)-child|(?:first|last|nth(?:-last)?+)-of-type|not\\([[:ascii:]]*\\)';
const PSEUDO_CLASS_MATCHER = 'empty|(?:first|last|nth(?:-last)?+|only)-(?:child|of-type)|not\\([[:ascii:]]*\\)';

/**
* @var bool[]
Expand Down
9 changes: 7 additions & 2 deletions tests/Unit/CssInlinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,12 @@ public function matchedCssDataProvider(): array
'div:last-of-type { %1$s }',
'<div class="div-3" style="%1$s">',
],
// broken: only-of-type (https://github.com/symfony/symfony/issues/33773)
// broken: only-of-type without preceding type
'type & :only-of-type => only child' => ['span:only-of-type { %1$s }', '<span style="%1$s">'],
'type & :only-of-type => only of that type' => [
'div:only-of-type { %1$s }',
'<div class="div-3" style="%1$s">',
],
// broken: nth-of-type without preceding type
'type & :nth-of-type(even) => 2nd of many of type' => [
'p:nth-of-type(even) { %1$s }',
Expand Down Expand Up @@ -903,6 +908,7 @@ public function nonMatchedCssDataProvider(): array
'type & :first-of-type => not last of many' => ['p:first-of-type { %1$s }', '<p class="p-7">'],
'type & :last-of-type => not 1st of many' => ['p:last-of-type { %1$s }', '<p class="p-1">'],
'type & :last-of-type => not 2nd last of many' => ['p:last-of-type { %1$s }', '<p class="p-6">'],
'type & :only-of-type => not one of many' => ['p:only-of-type { %1$s }', '<p class="p-1">'],
'type & :nth-of-type(even) => not 1st of many of type' => [
'p:nth-of-type(even) { %1$s }',
'<p class="p-1">',
Expand Down Expand Up @@ -2151,7 +2157,6 @@ public function matchingSelectorWithPseudoComponentCssRuleDataProvider(): array
];
$datasetsWithUnsupportedStaticPseudoClasses = [
':any-link' => ['a:any-link { color: green; }'],
':only-of-type' => ['a:only-of-type { color: green; }'],
':optional' => ['input:optional { color: green; }'],
':required' => ['input:required { color: green; }'],
];
Expand Down

0 comments on commit 86ca17d

Please sign in to comment.