Skip to content

Commit

Permalink
Don't parse tags other than links #24
Browse files Browse the repository at this point in the history
  • Loading branch information
Sommerregen committed Jul 9, 2018
1 parent 2386f49 commit 346bc43
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions classes/ExternalLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ class ExternalLinks
public function render($content, $options = [], $page = null)
{
// Get all <a> tags and process them
$content = preg_replace_callback('~<a[^>]*>.*?</a>~i',
$content = preg_replace_callback('~<a(?:\s[^>]*)?>.*?</a>~i',
function($match) use ($options, $page) {
// Load PHP built-in DOMDocument class
if (($dom = $this->loadDOMDocument($match[0])) === null) {
return $match[0];
}

$a = $dom->getElementsByTagName('a')->item(0);
// Check that there is really a link tag
$a = $dom->getElementsByTagName('a');
if ($a->length == 0) {
return $match[0];
}
$a = $a->item(0);

// Process links with non-empty href attribute
$href = $a->getAttribute('href');
Expand Down

0 comments on commit 346bc43

Please sign in to comment.