Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
feat: remove target="_blank" in internal links
Browse files Browse the repository at this point in the history
  • Loading branch information
zgq354 committed Dec 20, 2019
1 parent 67cbcb6 commit 208f628
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Formatter/Formatter.php
Expand Up @@ -136,14 +136,19 @@ protected function getConfigurator()
*/
protected function configureExternalLinks(Configurator $configurator)
{
$dom = $configurator->tags['URL']->template->asDOM();

foreach ($dom->getElementsByTagName('a') as $a) {
$a->setAttribute('target', '_blank');
$a->setAttribute('rel', 'nofollow');
}

$dom->saveChanges();
// Ignore internal links in a post
$baseURL = app()->url();
$tag = $configurator->tags['URL'];
$tag->template = <<<EOT
<xsl:choose>
<xsl:when test="starts-with(@url, '$baseURL')">
<a href="{@url}"><xsl:copy-of select="@title"/><xsl:apply-templates/></a>
</xsl:when>
<xsl:otherwise>
<a href="{@url}" target="_blank" rel="nofollow"><xsl:copy-of select="@title"/><xsl:apply-templates/></a>
</xsl:otherwise>
</xsl:choose>
EOT;
}

/**
Expand Down

0 comments on commit 208f628

Please sign in to comment.