Initial release
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MummertMedia\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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user