ritz078 / embed-js

🌻 A lightweight plugin to embed emojis, media, maps, tweets, code and more. ✨
https://codesandbox.io/s/Wp5OlNMn
MIT License
1.27k stars 88 forks source link

URLs parsing without 'http(s)' #193

Closed mario-lemes closed 7 years ago

mario-lemes commented 7 years ago

Hello @ritz078,

Why is not possible to linkify a url without http(s) protocol and only in the format like 'www.example.com'?

Thank you!

SnehaMidha commented 7 years ago

@ritz078 Changing return expression of toURL from (string.indexOf('//') === -1) ? ('//' + string) : string to (string.indexOf('http') ===-1)?('http://'+string):string works well for flickr, slideshare and instagram

and removal of https?:\/\/(?:[0-9A-Z-]+\.)? from regex.youtube works well for youtube

ritz078 commented 7 years ago

@SnehaMidha You have misunderstood the issue. The issue is only for normal urls where https://x.com is converted to URL but www.x.com is not converted to a url as the regex here doesn't identify the later as a valid URL. This has nothing to with services like instagram, youtube etc.

ishakalra commented 7 years ago

@ritz078 In the urlRegex function, the beginning says : (\b(https?|ftp|file):\/\/[^,.\s]+[^\s]*[^,.\s]+)|(?:https?:\/\/). So is it essentially looking for a URL which goes like https://https:// or ftp://https:// ? If this is the case, could you give us an example?

ritz078 commented 7 years ago

@ishakalra Hopefully this helps https://regex101.com/r/FkMl7i/1

sohamidha commented 7 years ago

@ritz078 Please check this link https://regex101.com/r/FkMl7i/2 This accepts www.github.com and others as well.

ritz078 commented 7 years ago

@sohamidha seems great. You can create a PR.

ritz078 commented 7 years ago

guys please don't make it a race to open a PR. Its tough for me 😄 . Try to open PRs for other issues. I understand this was the easiest one but I can help you for other issues too.