「www」/「http」の有無にかかわらず、リンクをリンクするのに苦労しています
これは私が得たものです:
noProtocolUrl = /\b((?:www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/g,
httpOrMailtoUrl = /\b((?:[a-z][\w-]+:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,
linkifier = function (html) {
return FormatLink(html
.replace(noProtocolUrl, '<a href="<``>://$1" rel="nofollow external" class="external_link">$1</a>') // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive
.replace(httpOrMailtoUrl, '<a href="$1" rel="nofollow external" class="external_link">$1</a>')
.replace(/"<``>/g, '"http')); // reinsert `"http`
http:// を使用した単純なリンクが linkify 処理を 2 回受けていることを除いて、うまく機能しています。
http://google.comは、 htttp://とhttp://google.comの 2 つのリンクになります。
これを修正する方法について何か考えはありますか?
ありがとう!
編集
まあ、私はhttp* と **wwwのようなbit.ly/fooのないリンクを除くすべてのリンクで動作するようにしました
誰かがそれらのリンクをキャッチする方法を知っていれば、大歓迎です。
var noProtocolUrl = /(^|["'(\s]|<)(www\..+?\..+?)((?:[:?]|\.+)?(?:\s|$)|>|[)"',])/g,
httpOrMailtoUrl = /\b((?:[a-z][\w-]+:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,
linkifier = function ( html ) {
return FormatLink(html
.replace( noProtocolUrl, '$1<a href="<``>://$2" rel="nofollow external" class="external_link">$2</a>$3' ) // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive
.replace( httpOrMailtoUrl, '<a href="$1" rel="nofollow external" class="external_link">$1</a>' )
.replace( /"<``>/g, '"http' )); // reinsert `"http`
},