public function addBaseurlToRelativeLinks($text, $baseurl, $callback)
    {
        $pattern = "#<a(.+?)href=\"([^\"]*)\"([.^>]*)>#";

        return preg_replace_callback(
            $pattern,
            function ($matches) use ($baseurl, $callback) {
                $url = $callback($matches[2], $baseurl);
                return "<a${matches[1]}href=\"$url\"${matches[3]}>";
            },
            $text
        );
    }