src/Ciconia/Extension/Core/LinkExtension.php
public function processAutoLink(Text $text)
    {
        if (!$text->contains('<')) {
            return;
        }

        $text->replace('{<((?:https?|ftp):[^\'">\s]+)>}', function (Text $w, Text $url) {
            $this->markdown->emit('escape.special_chars', [$url->replace('/(?<!\\\\)_/', '\\\\_')]);

            return $this->getRenderer()->renderLink($url, [
                'href' => $url->getString()
            ]);
        });

        /** @noinspection PhpUnusedParameterInspection */
        $text->replace('{
            <
            (?:mailto:)?
            (
                [-.\w]+
                \@
                [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
            )
            >
        }ix', function (Text $w, Text $address) {
            $address  = "mailto:" . $address;

            $encode = array(
                function ($char) { return '&#' . ord($char) . ';'; },
                function ($char) { return '&#x' . dechex(ord($char)) . ';'; },
                function ($char) { return $char; }
            );

            $chars = new Collection(str_split($address));

            $chars->apply(function ($char) use ($encode) {
                if ($char == '@') {
                    return $encode[rand(0, 1)]($char);
                } elseif ($char != ':') {
                    $rand = rand(0, 100);
                    $key = ($rand > 90) ? 2 : ($rand < 45 ? 0 : 1);

                    return $encode[$key]($char);
                }

                return $char;
            });

            $address = $chars->join();
            $text = $chars->slice(7)->join();

            return $this->getRenderer()->renderLink($text, ['href' => $address]);
        });
    }
public function processAutoLink(Text $text)
    {
        if (!$text->contains('<')) {
            return;
        }

        $text->replace('{<((?:https?|ftp):[^\'">\s]+)>}', function (Text $w, Text $url) {
            $this->markdown->emit('escape.special_chars', [$url->replace('/(?<!\\\\)_/', '\\\\_')]);

            return $this->getRenderer()->renderLink($url, [
                'href' => $url->getString()
            ]);
        });

        /** @noinspection PhpUnusedParameterInspection */
        $text->replace('{
            <
            (?:mailto:)?
            (
                [-.\w]+
                \@
                [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
            )
            >
        }ix', function (Text $w, Text $address) {
            $address  = "mailto:" . $address;

            $encode = array(
                function ($char) { return '&#' . ord($char) . ';'; },
                function ($char) { return '&#x' . dechex(ord($char)) . ';'; },
                function ($char) { return $char; }
            );

            $chars = new Collection(str_split($address));

            $chars->apply(function ($char) use ($encode) {
                if ($char == '@') {
                    return $encode[rand(0, 1)]($char);
                } elseif ($char != ':') {
                    $rand = rand(0, 100);
                    $key = ($rand > 90) ? 2 : ($rand < 45 ? 0 : 1);

                    return $encode[$key]($char);
                }

                return $char;
            });

            $address = $chars->join();
            $text = $chars->slice(7)->join();

            return $this->getRenderer()->renderLink($text, ['href' => $address]);
        });
    }
Make links out of things like `<http://example.com/>`

@param Text $text