Skip to content

Commit

Permalink
added optional options to noprocess (#2954)
Browse files Browse the repository at this point in the history
* added optional options to noprocess

* fix minor bug with skip and better naming

* Added tests

Signed-off-by: Andy Miller <rhuk@mac.com>

* Added some tests

Signed-off-by: Andy Miller <rhuk@mac.com>

Co-authored-by: Ricardo <ricardo@urbansquid.london>
Co-authored-by: Andy Miller <rhuk@mac.com>
  • Loading branch information
3 people authored Jul 7, 2020
1 parent 5b47e61 commit b94c4e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
10 changes: 7 additions & 3 deletions system/src/Grav/Common/Page/Markdown/Excerpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/Grav/Common/Helpers/ExcerptsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,34 @@ public function testProcessImageHtml()
Excerpts::processImageHtml('<img src="sample-image.jpg?classes=foo" alt="Sample Image" />', $this->page)
);
}

public function testNoProcess()
{
$this->assertStringStartsWith(
'<a href="https://play.google.com/store/apps/details?hl=de" id="org.jitsi.meet" target="_blank"',
Excerpts::processLinkHtml('<a href="https://play.google.com/store/apps/details?id=org.jitsi.meet&hl=de&target=_blank">regular process</a>')
);

$this->assertStringStartsWith(
'<a href="https://play.google.com/store/apps/details?id=org.jitsi.meet&hl=de&target=_blank"',
Excerpts::processLinkHtml('<a href="https://play.google.com/store/apps/details?id=org.jitsi.meet&hl=de&target=_blank&noprocess">noprocess</a>')
);

$this->assertStringStartsWith(
'<a href="https://play.google.com/store/apps/details?id=org.jitsi.meet&hl=de" target="_blank"',
Excerpts::processLinkHtml('<a href="https://play.google.com/store/apps/details?id=org.jitsi.meet&hl=de&target=_blank&noprocess=id">noprocess=id</a>')
);
}

public function testTarget()
{
$this->assertStringStartsWith(
'<a href="https://play.google.com/store/apps/details" target="_blank"',
Excerpts::processLinkHtml('<a href="https://play.google.com/store/apps/details?target=_blank">only target</a>')
);
$this->assertStringStartsWith(
'<a href="https://meet.weikamp.biz/Support" rel="nofollow" target="_blank"',
Excerpts::processLinkHtml('<a href="https://meet.weikamp.biz/Support?rel=nofollow&target=_blank">target and rel</a>')
);
}
}

0 comments on commit b94c4e7

Please sign in to comment.