From b94c4e775aa59bc653e440bbe0835ad489b1ce62 Mon Sep 17 00:00:00 2001 From: Ricardo Verdugo Date: Tue, 7 Jul 2020 19:27:32 +0100 Subject: [PATCH] added optional options to noprocess (#2954) * added optional options to noprocess * fix minor bug with skip and better naming * Added tests Signed-off-by: Andy Miller * Added some tests Signed-off-by: Andy Miller Co-authored-by: Ricardo Co-authored-by: Andy Miller --- .../Grav/Common/Page/Markdown/Excerpts.php | 10 +++++-- .../unit/Grav/Common/Helpers/ExcerptsTest.php | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Page/Markdown/Excerpts.php b/system/src/Grav/Common/Page/Markdown/Excerpts.php index f5dc274bf..63c4826ae 100644 --- a/system/src/Grav/Common/Page/Markdown/Excerpts.php +++ b/system/src/Grav/Common/Page/Markdown/Excerpts.php @@ -104,12 +104,16 @@ static function ($carry, $item) { // Valid attributes supported. $valid_attributes = Grav::instance()['config']->get('system.pages.markdown.valid_link_attributes'); + $skip = []; // Unless told to not process, go through actions. if (array_key_exists('noprocess', $actions)) { + $skip = is_bool($actions['noprocess']) ? $actions : explode(',', $actions['noprocess']); unset($actions['noprocess']); - } else { - // Loop through actions for the image and call them. - foreach ($actions as $attrib => $value) { + } + + // Loop through actions for the image and call them. + foreach ($actions as $attrib => $value) { + if (!in_array($attrib, $skip)) { $key = $attrib; if (in_array($attrib, $valid_attributes, true)) { diff --git a/tests/unit/Grav/Common/Helpers/ExcerptsTest.php b/tests/unit/Grav/Common/Helpers/ExcerptsTest.php index e344a8fdc..1d95f3c96 100644 --- a/tests/unit/Grav/Common/Helpers/ExcerptsTest.php +++ b/tests/unit/Grav/Common/Helpers/ExcerptsTest.php @@ -87,4 +87,34 @@ public function testProcessImageHtml() Excerpts::processImageHtml('Sample Image', $this->page) ); } + + public function testNoProcess() + { + $this->assertStringStartsWith( + 'regular process') + ); + + $this->assertStringStartsWith( + 'noprocess') + ); + + $this->assertStringStartsWith( + 'noprocess=id') + ); + } + + public function testTarget() + { + $this->assertStringStartsWith( + 'only target') + ); + $this->assertStringStartsWith( + 'target and rel') + ); + } }