Skip to content

Instantly share code, notes, and snippets.

@colinodell
Created July 14, 2017 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinodell/39256bed1e079dcf302af6d924880d12 to your computer and use it in GitHub Desktop.
Save colinodell/39256bed1e079dcf302af6d924880d12 to your computer and use it in GitHub Desktop.
<?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