私はこの素晴らしいプラグインを使用しています:https ://github.com/maranomynet/linkify/blob/master/1.0/jquery.linkify-1.0.js
domを操作するテキストをリンクします。問題は次のようなリンクにあります:http://en.wikipedia.org/wiki/The_Godfather_ (novel )
リンクは「http://en.wikipedia.org/wiki/The_Godfather_(novel」になります
括弧などを処理するためにlinkifyコードで何を変更できますか?
ありがとう!
PS:ねえ、Stackoverflowもこれを使用できるようです!ハハ;)
編集:
DaringFireballの投稿を見たところ、うまく機能しています...問題はwww.google.comのような単純なURLにあります(「noProtocolUrl」の最初の正規表現に関係していると思います。これは私が正しいことです。今:
var noProtocolUrl = /(^|["'(\s]|<)(www\..+?\..+?)((?:[:?]|\.+)?(?:\s|$)|>|[)"',])/g,
httpOrMailtoUrl = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:(?:[^\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`
},
「www.facebook.com」を使用すると、これを取得できます(リンクの横のテキストと同じように、rel属性とclass属性を使用します。
www.facebook.com" rel="nofollow external" class="external_link">www.facebook.com