App\services\Markdown::text PHP Method

text() public method

Add link to another articles
public text ( $text ) : mixed | string
$text
return mixed | string
    public function text($text)
    {
        if (preg_match(self::PATTERN_ARTICLE, $text, $matches) > 0) {
            $text = preg_replace_callback(self::PATTERN_ARTICLE, function ($matches) {
                return sprintf("<a href='%s'>%s</a>", route('articles.show', $matches['id']), $matches[0]);
            }, $text);
        }
        if (preg_match(self::PATTERN_REMOVE, $text, $matches) > 0) {
            $text = preg_replace_callback(self::PATTERN_REMOVE, function ($matches) {
                return '';
            }, $text);
        }
        if (preg_match(self::PATTERN_FRONT_FORMATTER, $text, $matches) > 0) {
            $text = preg_replace_callback(self::PATTERN_FRONT_FORMATTER, function ($matches) {
                return '';
            }, $text);
        }
        return parent::text($text);
    }
Markdown