for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Utils;
/**
* This class is a light interface between an external Markdown parser library
* and the application. It's generally recommended to create these light interfaces
* to decouple your application from the implementation details of the third-party library.
* @author Ryan Weaver <[email protected]>
* @author Javier Eguiluz <[email protected]>
class Markdown
{
private $parser;
private $purifier;
public function __construct()
$this->parser = new \Parsedown();
$purifierConfig = \HTMLPurifier_Config::create([
'Cache.DefinitionImpl' => null, // Disable caching
]);
$this->purifier = new \HTMLPurifier($purifierConfig);
}
public function toHtml(string $text): string
$html = $this->parser->text($text);
$safeHtml = $this->purifier->purify($html);
return $safeHtml;