Compare commits

..

9 Commits

Author SHA1 Message Date
Jérémy Dufraisse
4342526f6d fix(Pico::loadPlugins): use require once to be able to reload Pico 2023-03-21 08:53:30 +01:00
Jérémy Dufraisse
2e5f58f07d fix(API_VERSION): to prevent errors 2023-03-16 23:15:10 +01:00
Jérémy Dufraisse
0187138622 Merge branch 'fix/update-paresdown' into fix-compatibility-php8 2023-03-11 00:35:40 +01:00
Jérémy Dufraisse
fca0c92b60 fix(Pico): call to new parsedown 2023-02-27 09:06:39 +01:00
Jérémy Dufraisse
107cb3fafe fix(ParsedownExtra): update namespace 2023-02-22 19:40:18 +01:00
Jérémy Dufraisse
f26b87b9ae shore(composer): update parsedown 2023-02-22 19:27:37 +01:00
Jérémy Dufraisse
61283bdba7 fix(composer): be more stable when replacing picocms/pico 2023-01-24 11:20:23 +01:00
Jérémy Dufraisse
7fcaec07f5 feat(composer): declare replacement of picocms/pico 2023-01-24 10:50:46 +01:00
Jérémy Dufraisse
8a41bb6b94 fix(php8): be compatible 2023-01-24 10:34:22 +01:00
4 changed files with 32 additions and 26 deletions

View File

@ -31,12 +31,12 @@
"source": "https://github.com/picocms/Pico" "source": "https://github.com/picocms/Pico"
}, },
"require": { "require": {
"php": "^7.0.8", "php": "^7.0.8 || ^8.0",
"ext-mbstring": "*", "ext-mbstring": "*",
"twig/twig": "^2.12", "twig/twig": "^2.12",
"symfony/yaml" : "^3.4", "symfony/yaml" : "^3.4",
"erusev/parsedown": "1.7.4", "erusev/parsedown": "^2.0.0-beta-1",
"erusev/parsedown-extra": "0.8.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.",

View File

@ -1,5 +1,5 @@
--- ---
Logo: %theme_url%/img/pico-white.svg Logo: '%theme_url%/img/pico-white.svg'
Tagline: Making the web easy. Tagline: Making the web easy.
Social: Social:
- title: Visit us on GitHub - title: Visit us on GitHub

View File

@ -42,6 +42,12 @@
* @license http://opensource.org/licenses/MIT The MIT License * @license http://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
{ {
/** /**
@ -63,7 +69,7 @@ class Pico
* *
* @var int * @var int
*/ */
const API_VERSION = 3; const API_VERSION = 4;
/** /**
* Sort files in alphabetical ascending order * Sort files in alphabetical ascending order
@ -648,7 +654,7 @@ class Pico
{ {
// scope isolated require() // scope isolated require()
$includeClosure = function ($pluginFile) { $includeClosure = function ($pluginFile) {
require($pluginFile); require_once($pluginFile);
}; };
if (PHP_VERSION_ID >= 50400) { if (PHP_VERSION_ID >= 50400) {
$includeClosure = $includeClosure->bindTo(null); $includeClosure = $includeClosure->bindTo(null);
@ -1561,12 +1567,13 @@ class Pico
public function getParsedown() public function getParsedown()
{ {
if ($this->parsedown === null) { if ($this->parsedown === null) {
$className = $this->config['content_config']['extra'] ? 'ParsedownExtra' : 'Parsedown'; $state = new State([
$this->parsedown = new $className(); new Breaks((bool) $this->config['content_config']['breaks'])
]);
$this->parsedown->setBreaksEnabled((bool) $this->config['content_config']['breaks']); if ($this->config['content_config']['extra']){
$this->parsedown->setMarkupEscaped((bool) $this->config['content_config']['escape']); $state = new ParsedownExtra($state);
$this->parsedown->setUrlsLinked((bool) $this->config['content_config']['auto_urls']); }
$this->parsedown = new Parsedown($state);
$this->triggerEvent('onParsedownRegistered', array(&$this->parsedown)); $this->triggerEvent('onParsedownRegistered', array(&$this->parsedown));
} }
@ -1666,14 +1673,13 @@ 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
* *
* @return string parsed contents (HTML) * @return string parsed contents (HTML)
*/ */
public function parseFileContent($markdown, $singleLine = false) public function parseFileContent($markdown)
{ {
$markdownParser = $this->getParsedown(); $markdownParser = $this->getParsedown();
return !$singleLine ? @$markdownParser->text($markdown) : @$markdownParser->line($markdown); return @$markdownParser->toHtml($markdown);
} }
/** /**
@ -2102,12 +2108,12 @@ class Pico
if ($this->twig === null) { if ($this->twig === null) {
$twigConfig = $this->getConfig('twig_config'); $twigConfig = $this->getConfig('twig_config');
$twigLoader = new Twig_Loader_Filesystem($this->getThemesDir() . $this->getTheme()); $twigLoader = new \Twig\Loader\FilesystemLoader($this->getThemesDir() . $this->getTheme());
$this->twig = new Twig_Environment($twigLoader, $twigConfig); $this->twig = new \Twig\Environment($twigLoader, $twigConfig);
$this->twig->addExtension(new PicoTwigExtension($this)); $this->twig->addExtension(new PicoTwigExtension($this));
if (!empty($twigConfig['debug'])) { if (!empty($twigConfig['debug'])) {
$this->twig->addExtension(new Twig_Extension_Debug()); $this->twig->addExtension(new Twig\Extension\DebugExtension());
} }
// register content filter // register content filter
@ -2115,7 +2121,7 @@ class Pico
// this is the reason why we can't register this filter as part of PicoTwigExtension // this is the reason why we can't register this filter as part of PicoTwigExtension
$pico = $this; $pico = $this;
$pages = &$this->pages; $pages = &$this->pages;
$this->twig->addFilter(new Twig_SimpleFilter( $this->twig->addFilter(new \Twig\TwigFilter(
'content', 'content',
function ($page) use ($pico, &$pages) { function ($page) use ($pico, &$pages) {
if (isset($pages[$page])) { if (isset($pages[$page])) {
@ -2156,7 +2162,7 @@ class Pico
'theme_url' => $this->getConfig('themes_url') . $this->getTheme(), 'theme_url' => $this->getConfig('themes_url') . $this->getTheme(),
'site_title' => $this->getConfig('site_title'), 'site_title' => $this->getConfig('site_title'),
'meta' => $this->meta, 'meta' => $this->meta,
'content' => new Twig_Markup($this->content, 'UTF-8'), 'content' => new \Twig\Markup($this->content, 'UTF-8'),
'pages' => $this->pages, 'pages' => $this->pages,
'previous_page' => $this->previousPage, 'previous_page' => $this->previousPage,
'current_page' => $this->currentPage, 'current_page' => $this->currentPage,

View File

@ -67,20 +67,20 @@ class PicoTwigExtension extends Twig_Extension
* *
* @see Twig_ExtensionInterface::getFilters() * @see Twig_ExtensionInterface::getFilters()
* *
* @return Twig_SimpleFilter[] array of Pico's Twig filters * @return \Twig\TwigFilter[] array of Pico's Twig filters
*/ */
public function getFilters() public function getFilters()
{ {
return array( return array(
'markdown' => new Twig_SimpleFilter( 'markdown' => new \Twig\TwigFilter(
'markdown', 'markdown',
array($this, 'markdownFilter'), array($this, 'markdownFilter'),
array('is_safe' => array('html')) array('is_safe' => array('html'))
), ),
'map' => new Twig_SimpleFilter('map', array($this, 'mapFilter')), 'map' => new \Twig\TwigFilter('map', array($this, 'mapFilter')),
'sort_by' => new Twig_SimpleFilter('sort_by', array($this, 'sortByFilter')), 'sort_by' => new \Twig\TwigFilter('sort_by', array($this, 'sortByFilter')),
'link' => new Twig_SimpleFilter('link', array($this->pico, 'getPageUrl')), 'link' => new \Twig\TwigFilter('link', array($this->pico, 'getPageUrl')),
'url' => new Twig_SimpleFilter('url', array($this->pico, 'substituteUrl')) 'url' => new \Twig\TwigFilter('url', array($this->pico, 'substituteUrl'))
); );
} }