From e8795f158ecf6ace4394f5b8b274b97d80cf5587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Mon, 25 Dec 2023 13:57:47 +0100 Subject: [PATCH] shore(composer): update parsedown and update namespace BREAKING_CHANGE : Pico::parseFileContent parameter $singleLineis not needed BREAKING_CHANGE : $config['content_config']['escape'] and $config['content_config']['auto_urls'] are not used --- composer.json | 4 ++-- lib/Pico.php | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index ff92e9d..20cf8a3 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,8 @@ "ext-mbstring": "*", "twig/twig": "^3.3.8", "symfony/yaml" : "^5.4.3", - "erusev/parsedown": "1.7.4", - "erusev/parsedown-extra": "0.8.1" + "erusev/parsedown": "^2.0.0-beta-1", + "erusev/parsedown-extra": "^2.0.0-beta-1" }, "suggest": { "picocms/pico-theme": "Pico requires a theme to actually display the contents of your website. This is Pico's official default theme.", diff --git a/lib/Pico.php b/lib/Pico.php index 653380f..d80a837 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -61,6 +61,12 @@ use Twig\TwigFilter; * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ + +use Erusev\Parsedown\Configurables\Breaks; +use Erusev\Parsedown\Parsedown; +use Erusev\Parsedown\State; +use Erusev\ParsedownExtra\ParsedownExtra; + class Pico { /** @@ -1587,15 +1593,13 @@ class Pico public function getParsedown(): Parsedown { if ($this->parsedown === null) { - if ($this->config['content_config']['extra']) { - $this->parsedown = new ParsedownExtra(); - } else { - $this->parsedown = new Parsedown(); + $state = new State([ + new Breaks((bool) $this->config['content_config']['breaks']) + ]); + if ($this->config['content_config']['extra']){ + $state = new ParsedownExtra($state); } - - $this->parsedown->setBreaksEnabled((bool) $this->config['content_config']['breaks']); - $this->parsedown->setMarkupEscaped((bool) $this->config['content_config']['escape']); - $this->parsedown->setUrlsLinked((bool) $this->config['content_config']['auto_urls']); + $this->parsedown = new Parsedown($state); $this->triggerEvent('onParsedownRegistered', [ &$this->parsedown ]); } @@ -1711,14 +1715,14 @@ class Pico * @see Pico::getFileContent() * * @param string $markdown Markdown contents of a page - * @param bool $singleLine whether to parse just a single line of markup + * @param bool $singleLine whether to parse just a single line of markup (deprecated because not needed and not used) * * @return string parsed contents (HTML) */ public function parseFileContent(string $markdown, bool $singleLine = false): string { $markdownParser = $this->getParsedown(); - return !$singleLine ? @$markdownParser->text($markdown) : @$markdownParser->line($markdown); + return @$markdownParser->toHtml($markdown); } /**