Linkify some text:
Some things probably shouldn't match:
- test.xyz
- test.xyz/
- test.xyz/foo
- [test.xyz]
- [test.xyz/]
- [test.xyz/foo]
- "http://benalman.a"
- "http://benalman.a/"
- [http://benalman.com]x
- 100.200.300.400
- 1000.2.3.4
- 1.2.3
- 100.200.300.400/foo
- 1000.2.3.4/foo
- 1.2.3/foo
- a1.2.3.4
- 1.2.3.4a
- example.coma
- -example.coma
- path:to:file.pm
- /path/to/file.pl
But many things should:
- This is a bad link test.xyz/ and a few linkinus2-reg://a-b-c good 1.2.3.4 links [http://benalman.com] http://benalman.com/(url) together (http://benalman.com/(url)) here.
- This is a bad link 100.200.300.400/foo and a few example.com good example.com?x=1 links http://[email protected] together "http://benalman.com/(url)" "http://benalman.com/" here.
- some bold and italics: benalman.com, benalman.com/, benalman.com/foo, http://benalman.com, http://benalman.com/, [email protected]
- test (benalman.com), and (http://benalman.com/), and [foo.com,] {bar.com!}
- International domain names føøbár.ch (føøbár.ch) "føø-bár.ch" føø.bár.ch føøbár.ch/føø/bár should be linkified, but føø_bár.ch is not valid
- linkinus2-reg://a-b-c
- <1.2.3.4>
- <http://1.2.3.4>
- <http://1.2.3.4/>
- «http://1.2.3.4/»
- "http://1.2.3.4/"
- <http://1.2.3.4/>
- "http://1.2.3.4/"
- [email protected]
- mailto:[email protected]
- "[email protected]"
- "mailto:[email protected]"
- [email protected]?
- mailto:[email protected]?
- [email protected].
- mailto:[email protected].
- [email protected]?subject=Test%20subject&body=Hello%20there!
- ftp.example.com
- irc.example.com
- ftp://ftp.example.com
- irc://irc.example.com
- ftp.example.com/foo
- irc.example.com/foo
- ftp://ftp.example.com/foo
- irc://irc.example.com/foo
- a 1.2.3.4
- 1.2.3.4 a
- a 1.2.3.4 a
- 1.2.3.4
- 1.2.3.4/foo
- ftp://1.2.3.4
- ftp://1.2.3.4/foo
- 101.102.103.104
- [email protected]
- omg-ponies://this:is:some:crap
- a [http://benalman.com]
- [http://benalman.com] b
- a [http://benalman.com] b
- [http://benalman.com]
- [http://benalman.com]
- [http://benalman.com]
- [http://benalman.com/]
- (http://benalman.com)
- (http://benalman.com/)
- "http://benalman.com"
- "http://benalman.com/"
- http://benalman.com/(url)
- "http://benalman.com/(url)"
- (http://benalman.com/(url))
- example.com
- example.com/
- example.tv
- example.tv/
- example.com?
- example.com/?
- (foo.com)
- "foo.com"
- [foo.com]
- [foo.com/]
- [foo.com/test]
- [foo.com/test/]
- example.com/foo
- example.com/foo/
- example.com?x=1
- example.com#y=2
- example.com?x=1#y=2
- example.tv
- test.example.com
- file:///foo.txt
- http://benalman.com
- http://benalman.com/
- http://benalman.xyz
- http://benalman.xyz/
- http://benalman.com?
- http://benalman.com/?
- http://benalman.xyz?
- http://benalman.xyz/?
- http://benalman.com"
- http://benalman.com/"
- http://benalman.xyz"
- http://benalman.xyz/"
- http://[email protected]
- http://foo:[email protected]
- http://benalman.com:81
- http://benalman.com:81/
- http://[email protected]:81/
- https://[email protected]:81/
parseuri examples
$(function(){
// jQuery is used for this example, but JavaScript Linkify doesn't require
// any third-party libraries.
$('li').each(function(){
var that = $(this),
txt = that.html(),
options = {
callback: function( text, href ) {
href && debug.log([ text, href ]);
return href ? '<a href="' + href + '" title="' + href + '">' + text + '</a>' : text;
}
};
that.html( txt + ' (orig)<br/>' + linkify( txt, options ) + ' (linkified)' );
});
});