gpt4 book ai didi

jQuery Linkify 插件 : Can't handle links that end in parenthesis

转载 作者:行者123 更新时间:2023-12-01 05:06:04 25 4
gpt4 key购买 nike

我正在使用这个很棒的插件: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_(小说”

我可以在 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

最佳答案

据我所知,the regex expression found here (最初由 John Gruber of Daring Fireball 创建,由 naren1012 修改)似乎可以解决问题。

要实现,请替换以下代码:

 var noProtocolUrl = /(^|["'(\s]|&lt;)(www\..+?\..+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,
httpOrMailtoUrl = /(^|["'(\s]|&lt;)((?:(?:https?|ftp):\/\/|mailto:).+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/g,
linkifier = function ( html ) {
return html
.replace( noProtocolUrl, '$1<a href="<``>://$2">$2</a>$3' ) // NOTE: we escape `"http` as `"<``>` to make sure `httpOrMailtoUrl` below doesn't find it as a false-positive
.replace( httpOrMailtoUrl, '$1<a href="$2">$2</a>$3' )
.replace( /"<``>/g, '"http' ); // reinsert `"http`
},

使用此代码:

 var noProtocolUrl = /(^|["'(\s]|&lt;)(www\..+?\..+?)((?:[:?]|\.+)?(?:\s|$)|&gt;|[)"',])/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 html
.replace( noProtocolUrl, '$1<a href="<``>://$2">$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">$1</a>')
.replace( /"<``>/g, '"http' ); // reinsert `"http`
},

关于jQuery Linkify 插件 : Can't handle links that end in parenthesis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5858851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com