michelf / php-markdown

Parser for Markdown and Markdown Extra derived from the original Markdown.pl by John Gruber.
http://michelf.ca/projects/php-markdown/
Other
3.42k stars 530 forks source link

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

Open jlgrall opened 10 years ago

jlgrall commented 10 years ago

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.

michelf commented 10 years ago

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

jlgrall commented 10 years ago

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

michelf commented 10 years ago

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

markseuffert commented 10 years ago

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

ghost commented 10 years ago

+1

markseuffert commented 10 years ago

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.

taufik-nurrohman commented 9 years ago

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

MrPetovan commented 5 years ago

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.

aaronpk commented 4 years ago

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.