30 lines
684 B
PHP
30 lines
684 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mummert\NewsSubmissionBundle\Service;
|
|
|
|
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
|
|
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
|
|
|
|
class NewsContentSanitizer
|
|
{
|
|
private readonly HtmlSanitizer $sanitizer;
|
|
|
|
public function __construct()
|
|
{
|
|
$config = new HtmlSanitizerConfig();
|
|
|
|
foreach (['p', 'h2', 'h3', 'strong', 'em', 'u', 'ul', 'ol', 'li'] as $tag) {
|
|
$config = $config->allowElement($tag);
|
|
}
|
|
|
|
$this->sanitizer = new HtmlSanitizer($config);
|
|
}
|
|
|
|
public function sanitize(string $html): string
|
|
{
|
|
return trim($this->sanitizer->sanitize($html));
|
|
}
|
|
}
|