dwyl / ampl

:iphone: :zap: Ampl transforms Markdown into AMP-compliant html so it loads super-fast!
GNU General Public License v2.0
58 stars 3 forks source link

Automatic detection of URLs in markdown #21

Open iteles opened 8 years ago

iteles commented 8 years ago

It would be a nice enhancement (low priority) to automatically detect URLs in the markdown and convert them into HTML links <a> elements.

This example is from: http://ampl-demo.herokuapp.com/dwyl/learn-react

non-detected-urls
des-des commented 8 years ago

:+1:

pankajpatel commented 7 years ago

/(https?:)*\/\/[\w.\/?&@:%._\+~#=]*\b/g can be used to detect URLs and replace with links. http://regexr.com/3f3bq

const text = `foo@demo.net  bar.ba@test.co.uk
www.demo.com    http://foo.co.uk/x
http://regexr.com/foo.html?q=bar&baz=new&q=a+b
https://mediatemple.net
//www.google.com
demo.google.com`;

let formatedText = text.replace(
  /((https?:)*\/\/[\w.\/?&@:%._\+~#=]*\b)/gi,
  '<a href="$1">$1</a>'
);
console.log( formatedText );
des-des commented 7 years ago

Currently I think this is being done by remarkable