Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
🐛 kirbytag with ratio does work again. thanks @colin-johnston
Browse files Browse the repository at this point in the history
closes #21

Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Mar 9, 2020
1 parent 26a3c6e commit 33cd632
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
6 changes: 4 additions & 2 deletions 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": [
Expand All @@ -25,7 +25,9 @@
"img",
"lazyload",
"kirbytag",
"editor-block"
"editor-block",
"component",
"markdown"
],
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion index.php
Expand Up @@ -49,14 +49,42 @@
\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);
return $srcsetTag->html();
},
],
],
'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, '<style>.lazysrcset-ratio[data-ratio');
if ($srcsetPluginWithRatio) {
$text = '<srcsetplugin>' . $text . '</srcsetplugin>';
}

$text = $markdown->parse($text, $inline);

if ($srcsetPluginWithRatio) {
$text = preg_replace_callback('/<\/?srcsetplugin>/', function () {
return '';
}, $text);
}

return $text;
}
],
'api' => [
'routes' => [
[
Expand Down
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -17,6 +17,7 @@ This plugin extends the core `(image: )`-Kirbytag. All params that work for `(im
- `data-sizes="auto"` attribute
- `data-thumb-srcset` attribute printing the srcset array as json (only when debugging)
- `data-ratio` attribute with ratio of the image to parent of `img` element
- It registers a custom markdown component since needs to wrap and unwrap the markdown.

## TOC

Expand Down

0 comments on commit 33cd632

Please sign in to comment.