From 33cd632a9e59c4265d2f9f23debcb58c3eea774b Mon Sep 17 00:00:00 2001 From: Bruno Meilick Date: Mon, 9 Mar 2020 16:29:55 +0000 Subject: [PATCH] :bug: kirbytag with ratio does work again. thanks @colin-johnston closes #21 Signed-off-by: Bruno Meilick --- composer.json | 6 ++++-- composer.lock | 2 +- index.php | 30 +++++++++++++++++++++++++++++- readme.md | 1 + 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 49b123c..4e1d20f 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "bnomei/kirby3-srcset", "type": "kirby-plugin", - "version": "3.3.2", + "version": "3.3.3", "license": "MIT", "description": "Kirby 3 Plugin for creating lazyloading image srcset", "authors": [ @@ -25,7 +25,9 @@ "img", "lazyload", "kirbytag", - "editor-block" + "editor-block", + "component", + "markdown" ], "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 08b5cc9..ddf67ce 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f63d898e13f0d8059003f77c56319612", + "content-hash": "cb35bc67067902fd38e9fbdd177c3934", "packages": [ { "name": "getkirby/composer-installer", diff --git a/index.php b/index.php index 6ced57b..331d7ba 100644 --- a/index.php +++ b/index.php @@ -49,7 +49,7 @@ \Bnomei\Srcset::kirbytagAttrs() ), 'html' => function ($tag) { - if ($tag === null) { + if ($tag === null || $tag->parent()->file($tag->value) === null) { return \Kirby\Cms\Html::img('', ['alt' => 'lazysrcset can not create srcset from null']); } $srcsetTag = new \Bnomei\Srcset($tag); @@ -57,6 +57,34 @@ }, ], ], + 'components' => [ + 'markdown' => function (Kirby $kirby, string $text = null, array $options = [], bool $inline = false) { + static $markdown; + static $config; + + // if the config options have changed or the component is called for the first time, + // (re-)initialize the parser object + if ($config !== $options) { + $markdown = new \Kirby\Text\Markdown($options); + $config = $options; + } + + $srcsetPluginWithRatio = \Kirby\Toolkit\Str::startsWith($text, '