Bläddra i källkod

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
Jérémy Dufraisse 2 år sedan
förälder
incheckning
eb9caf22fe
2 ändrade filer med 16 tillägg och 12 borttagningar
  1. 2 2
      composer.json
  2. 14 10
      lib/Pico.php

+ 2 - 2
composer.json

@@ -35,8 +35,8 @@
         "ext-mbstring": "*",
         "ext-mbstring": "*",
         "twig/twig": "^3.3.8",
         "twig/twig": "^3.3.8",
         "symfony/yaml" : "^5.4.3",
         "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": {
     "suggest": {
         "picocms/pico-theme": "Pico requires a theme to actually display the contents of your website. This is Pico's official default theme.",
         "picocms/pico-theme": "Pico requires a theme to actually display the contents of your website. This is Pico's official default theme.",

+ 14 - 10
lib/Pico.php

@@ -61,6 +61,12 @@ use Twig\TwigFilter;
  * @license https://opensource.org/licenses/MIT The MIT License
  * @license https://opensource.org/licenses/MIT The MIT License
  * @version 3.0
  * @version 3.0
  */
  */
+
+use Erusev\Parsedown\Configurables\Breaks;
+use Erusev\Parsedown\Parsedown;
+use Erusev\Parsedown\State;
+use Erusev\ParsedownExtra\ParsedownExtra;
+
 class Pico
 class Pico
 {
 {
     /**
     /**
@@ -1587,15 +1593,13 @@ class Pico
     public function getParsedown(): Parsedown
     public function getParsedown(): Parsedown
     {
     {
         if ($this->parsedown === null) {
         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 ]);
             $this->triggerEvent('onParsedownRegistered', [ &$this->parsedown ]);
         }
         }
@@ -1711,14 +1715,14 @@ class Pico
      * @see Pico::getFileContent()
      * @see Pico::getFileContent()
      *
      *
      * @param string $markdown   Markdown contents of a page
      * @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)
      * @return string parsed contents (HTML)
      */
      */
     public function parseFileContent(string $markdown, bool $singleLine = false): string
     public function parseFileContent(string $markdown, bool $singleLine = false): string
     {
     {
         $markdownParser = $this->getParsedown();
         $markdownParser = $this->getParsedown();
-        return !$singleLine ? @$markdownParser->text($markdown) : @$markdownParser->line($markdown);
+        return @$markdownParser->toHtml($markdown);
     }
     }
 
 
     /**
     /**