php-markdown icon indicating copy to clipboard operation
php-markdown copied to clipboard

[feature request] Real URL autolinking (like in Github Flavored Markdown)

Open jlgrall opened this issue 11 years ago • 9 comments

Please, add an option to allow automatic linking of the URLs in texts even when they are not surrounded by angle brackets.

See URL autolinking in Github Flavored Markdown.

See extension autolink_bare_uris in Pandoc.

jlgrall avatar Jan 25 '14 20:01 jlgrall

I guess that could work as an option. There's still some thinking to do to figure out a good URL detection pattern though.

michelf avatar Feb 01 '14 03:02 michelf

It might be easier to look at an already existing Firefox extension or Greasemonkey extension that does URL autolinking for webpages in the browser.

jlgrall avatar Feb 05 '14 14:02 jlgrall

Noting this for reference: http://daringfireball.net/2010/07/improved_regex_for_matching_urls

michelf avatar Feb 16 '14 21:02 michelf

+1 like. It would be handy for content writers.

markseuffert avatar Mar 03 '14 14:03 markseuffert

+1

ghost avatar Mar 29 '14 00:03 ghost

I'm suggesting the following URL detection pattern.

function doAutoLinks($text)
{
    ...
    $text = preg_replace_callback("/((http|https|ftp):\/\/\S+[^\'\"\,\.\;\:\s]+)/", array(&$this, "_doAutoLinks_url_callback"), $text);
    $text = preg_replace_callback("/([\w\-\.]+@[\w\-\.]+\.[\w]{2,4})/", array(&$this, "_doAutoLinks_email_callback"), $text);
    return $text;
}

Here are some test cases.

markseuffert avatar Jun 18 '14 08:06 markseuffert

Another PHP regex for matching the URL patterns → http://jmrware.com/articles/2010/linkifyurl/linkify.html

taufik-nurrohman avatar Mar 02 '15 09:03 taufik-nurrohman

I would be interested in this feature as well. Typically, it would take the form of an autolink boolean flag on the MarkdownExtra class that enables/disables autolinking URLs in paragraphs.

The reason why this operation is desirable inside the Markdown parser is that it is neither practical to do it before nor after the Markdown conversion because URLs can be present inside tags, attributes, etc... and shouldn't be converted.

It is a problem for us over at friendica/friendica because we receive Markdown texts from Diaspora* that's using RedCarpet for displaying their message, and the RedCarpet markdown parser has an autolink feature, which allows Diaspora users to leave URLs as is in paragraphs to be transformed in HTML links.

Consequently, when we receive such Markdown text in Friendica, users are expecting to see the resulting post the same way it looked on Diaspora, with the URLs transformed in HTML links.

I've found another PHP Markdown parser library that has an autolinker feature (https://github.com/erusev/parsedown-extra) but I'd prefer to stick with this one as we are familiar with it and we don't know if they support the same options as yours.

MrPetovan avatar Mar 06 '19 15:03 MrPetovan

I would also like to see this! It is kind of annoying that I have to first pre-process my markdown to turn bare links into markdown links in order to support this.

aaronpk avatar Sep 09 '20 19:09 aaronpk