mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 21:56:25 +02:00
feat(core): Markdown parsing should be cached in production #287
This commit is contained in:
@@ -34,7 +34,6 @@ use League\Glide\Responses\SlimResponseFactory;
|
||||
use League\Glide\ServerFactory;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use ParsedownExtra as Markdown;
|
||||
use Slim\Csrf\Guard;
|
||||
use Slim\Flash\Messages;
|
||||
use Slim\Http\Environment;
|
||||
@@ -202,12 +201,6 @@ $flextype['shortcodes'] = static function ($container) {
|
||||
return new ShortcodeFacade();
|
||||
};
|
||||
|
||||
/**
|
||||
* Add Markdown service to Flextype container
|
||||
*/
|
||||
$flextype['markdown'] = static function ($container) {
|
||||
return new Markdown();
|
||||
};
|
||||
|
||||
/**
|
||||
* Add entries service to Flextype container
|
||||
|
36
flextype/parsers/MarkdownParser.php
Normal file
36
flextype/parsers/MarkdownParser.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @link http://flextype.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use ParsedownExtra;
|
||||
|
||||
class MarkdownParser
|
||||
{
|
||||
|
||||
/**
|
||||
* Markdown Object
|
||||
*
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
private static $markdown = null;
|
||||
|
||||
/**
|
||||
* parse
|
||||
*/
|
||||
public static function parse($input) : string
|
||||
{
|
||||
!isset(self::$markdown) and self::$markdown = new ParsedownExtra();
|
||||
|
||||
return self::$markdown->text($input);
|
||||
}
|
||||
}
|
@@ -44,10 +44,6 @@ class MarkdownTwigExtension extends Twig_Extension
|
||||
*/
|
||||
public function markdown($value) : string
|
||||
{
|
||||
if ($value !== null) {
|
||||
return $this->flextype->markdown->text($value);
|
||||
}
|
||||
|
||||
return '';
|
||||
return MarkdownParser::parse($value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user