-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement consistent HTML preservation modifier
- Loading branch information
Showing
4 changed files
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\View\Modifications; | ||
|
||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
class HTMLCleanseModifier extends HTMLModifier | ||
{ | ||
/** | ||
* @param string $content The HTML content to be modified. | ||
* @param \Closure $next The next method in the middleware pipeline. | ||
* | ||
* @return mixed The modified HTML content. | ||
*/ | ||
public function handle(string $content, \Closure $next) | ||
{ | ||
$crawler = new Crawler(); | ||
$crawler->addHtmlContent(mb_convert_encoding($content, 'UTF-8')); | ||
$content = $crawler->filterXpath('//body')->first()->html(); | ||
|
||
return $next($content); | ||
} | ||
} |