Created
July 14, 2017 12:40
-
-
Save colinodell/39256bed1e079dcf302af6d924880d12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class TargetBlankLinkProcessor implements DocumentProcessorInterface | |
{ | |
/** | |
* @param Document $document | |
* | |
* @return void | |
*/ | |
public function processDocument(Document $document) | |
{ | |
$walker = $document->walker(); | |
while ($event = $walker->next()) { | |
$node = $event->getNode(); | |
// Only stop at Link nodes when we first encounter them | |
if (!($node instanceof Link) || !$event->isEntering()) { | |
continue; | |
} | |
$node->data['attributes']['target'] = '_blank'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment