public function InlineLinkExtractor::extract in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 2.x src/LinkExtractor/InlineLinkExtractor.php \Drupal\printable\LinkExtractor\InlineLinkExtractor::extract()
Highlight hrefs from links in the given HTML string.
Parameters
string $string: The HTML string to extract links from.
Return value
string The HTML string, with links highlighted.
Overrides LinkExtractorInterface::extract
File
- src/
LinkExtractor/ InlineLinkExtractor.php, line 48
Class
- InlineLinkExtractor
- Link extractor.
Namespace
Drupal\printable\LinkExtractorCode
public function extract($string) {
$this->crawler
->addContent($string);
$this->crawler
->filter('a')
->each(function (HtmlPageCrawler $anchor, $uri) {
$href = $anchor
->attr('href');
if ($href) {
$url = $this
->urlFromHref($href);
$anchor
->append(' (' . $url
->toString() . ')');
}
});
return (string) $this->crawler;
}