picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 615 forks source link

Plugin proposal: a better support for images #504

Closed anasram closed 4 years ago

anasram commented 4 years ago

Recently I found a Parsedown extension wraps single-image lines in <figure> element instead of <p>: FigureExtParsedown.class.php.

Any one here interested to build a Pico plugin based on it?

Notice that this gist still lacks several features:

PhrozenByte commented 4 years ago

Try creating a plugin like the following:

class FigureExtParsedownPicoPlugin extends AbstractPicoPlugin
{
    public function onParsedownRegistered(Parsedown &$parsedown)
    {
        $config = $this->getPico()->getConfig();

        $parsedown = new FigureExtParsedown();
        $parsedown->setBreaksEnabled((bool) $config['content_config']['breaks']);
        $parsedown->setMarkupEscaped((bool) $config['content_config']['escape']);
        $parsedown->setUrlsLinked((bool) $config['content_config']['auto_urls']);
    }
}
anasram commented 4 years ago

Okay? then? 😕

Actually, I don't speak PHP 😳

Maybe I had to write this issue in a different way:

Plugin Proposal

Any one here interested to build a Pico plugin based on FigureExtParsedown Class gist?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:

PhrozenByte commented 4 years ago

Not sure whether someone is going to create a "real" plugin for it and particularly implement the additional features you were asking for, however, the code I provided should do at least the basic job of wrapping images in <figure>.

Simply create a plugins/FigureExtParsedownPicoPlugin/ folder, copy the FigureExtParsedown.php from the gist to this folder and create a FigureExtParsedownPicoPlugin.php with the following contents:

class FigureExtParsedownPicoPlugin extends AbstractPicoPlugin
{
    public function __construct(Pico $pico)
    {
        parent::__construct($pico);
        require_once(__DIR__ . '/FigureExtParsedown.php');
    }

    public function onParsedownRegistered(Parsedown &$parsedown)
    {
        $config = $this->getPico()->getConfig();

        $parsedown = new FigureExtParsedown();
        $parsedown->setBreaksEnabled((bool) $config['content_config']['breaks']);
        $parsedown->setMarkupEscaped((bool) $config['content_config']['escape']);
        $parsedown->setUrlsLinked((bool) $config['content_config']['auto_urls']);
    }
}
anasram commented 4 years ago

Here's it so far: FigureExtParsedownPicoPlugin.zip.

Didn't work; still wrapping images in <p>.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:

PhrozenByte commented 4 years ago

Whoops, there's the API version missing...


class FigureExtParsedownPicoPlugin extends AbstractPicoPlugin
{
    const API_VERSION = 2;

    public function __construct(Pico $pico)
    {
        parent::__construct($pico);
        require_once(__DIR__ . '/FigureExtParsedown.php');
    }

    public function onParsedownRegistered(Parsedown &$parsedown)
    {
        $config = $this->getPico()->getConfig();

        $parsedown = new FigureExtParsedown();
        $parsedown->setBreaksEnabled((bool) $config['content_config']['breaks']);
        $parsedown->setMarkupEscaped((bool) $config['content_config']['escape']);
        $parsedown->setUrlsLinked((bool) $config['content_config']['auto_urls']);
    }
}
anasram commented 4 years ago

Great, Thank you so much!

It works properly now.

After considering a figcaption bug, here's the final work: FigureExtParsedownPicoPlugin.zip.

I think it will be nice if you could publish it officially, with the following TODO list:

PhrozenByte commented 4 years ago

I've published it in our Wiki, see here

anasram commented 4 years ago

Thanx!