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 <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>
This commit is contained in:
Ricardo Verdugo
2020-07-07 19:27:32 +01:00
committed by GitHub
parent 5b47e6130c
commit b94c4e775a
2 changed files with 37 additions and 3 deletions

View File

@@ -104,12 +104,16 @@ class Excerpts
// 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)) {

View File

@@ -87,4 +87,34 @@ class ExcerptsTest extends \Codeception\TestCase\Test
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>')
);
}
}