PHP Parsedown, add target=_blank to links
In case you want all your links in your markdown to open in a new tab, you might want to add target="_blank"
systematically. You can do it with Parsedown
. However, I now use CommonMark
. I'm not really sure why I changed & I'm not sure how to do this in common mark.
<?php
if (!class_exists('MyParsedown')){
class MyParsedown extends Parsedown {
protected function inlineLink($excerpt){
$link = parent::inlineLink($excerpt);
if (!isset($link))return null;
$link['element']['attributes']['target'] = '_blank';
// var_dump($link);
// throw new \Exception('love cats');
return $link;
}
}
}