Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLEANUP] Rename HtmlPruner::removeInvisibleNodes … #718

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
[#698](https://github.com/MyIntervals/emogrifier/pull/698))

### Changed
- Rename `HtmlPruner::removeInvisibleNodes` to
`HtmlPruner::removeElementsWithDisplayNone`
([#717](https://github.com/MyIntervals/emogrifier/issues/717),
[#718](https://github.com/MyIntervals/emogrifier/pull/718))
- Mark the utility classes as internal
([#715](https://github.com/MyIntervals/emogrifier/pull/715))
- Move utility classes to the `Pelago\Emogrifier\Utilities` namespace
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can also use the `DOMDocument` created by `CssInliner` to process it further
```php
$domDocument = \Pelago\Emogrifier\CssInliner::fromHtml($html)->inlineCss($css)->getDomDocument();
$prunedHtml = \Pelago\Emogrifier\HtmlProcessor\HtmlPruner::fromDomDocument($domDocument)
->removeInvisibleNodes->render();
->removeElementsWithDisplayNone()->render();
```

### Normalizing and cleaning up HTML
Expand Down
16 changes: 8 additions & 8 deletions src/Emogrifier/HtmlProcessor/HtmlPruner.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ class HtmlPruner extends AbstractHtmlProcessor
const DISPLAY_NONE_MATCHER = '//*[contains(translate(translate(@style," ",""),"NOE","noe"),"display:none")]';

/**
* Removes nodes that have a "display: none;" style.
* Removes elements that have a "display: none;" style.
*
* @return self fluent interface
*/
public function removeInvisibleNodes()
public function removeElementsWithDisplayNone()
{
$nodesWithStyleDisplayNone = $this->xPath->query(self::DISPLAY_NONE_MATCHER);
if ($nodesWithStyleDisplayNone->length === 0) {
$elementsWithStyleDisplayNone = $this->xPath->query(self::DISPLAY_NONE_MATCHER);
if ($elementsWithStyleDisplayNone->length === 0) {
return $this;
}

/** @var \DOMNode $node */
foreach ($nodesWithStyleDisplayNone as $node) {
$parentNode = $node->parentNode;
/** @var \DOMNode $element */
foreach ($elementsWithStyleDisplayNone as $element) {
$parentNode = $element->parentNode;
if ($parentNode !== null) {
$parentNode->removeChild($node);
$parentNode->removeChild($element);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Emogrifier/HtmlProcessor/HtmlPrunerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public function fromDomDocumentReturnsInstanceOfCalledClass()
/**
* @test
*/
public function removeInvisibleNodesProvidesFluentInterface()
public function removeElementsWithDisplayNoneProvidesFluentInterface()
{
$subject = HtmlPruner::fromHtml('<html></html>');

$result = $subject->removeInvisibleNodes();
$result = $subject->removeElementsWithDisplayNone();

self::assertSame($subject, $result);
}
Expand All @@ -77,11 +77,11 @@ public function displayNoneDataProvider()
*
* @dataProvider displayNoneDataProvider
*/
public function removeInvisibleNodesRemovesNodesWithDisplayNone($displayNone)
public function removeElementsWithDisplayNoneRemovesElementsWithDisplayNone($displayNone)
{
$subject = HtmlPruner::fromHtml('<html><body><div style="' . $displayNone . '"></div></body></html>');

$subject->removeInvisibleNodes();
$subject->removeElementsWithDisplayNone();

self::assertNotContains('<div', $subject->render());
}
Expand Down