[英]Javascript + Convert “<b>” to actual bold font
I am using the jTwitter plugin to get Twitter feeds. 我正在使用jTwitter插件来获取Twitter提要。 I am using it combined with a function that makes the links in the returned text click-able.
我正在使用它与一个功能,使返回的文本中的链接可单击。
That function looks like this: 该函数如下所示:
function replaceURLWithHTMLLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"<a href='$1' target='_blank'>$1</a>");
}
Everything works fine, except that the person who is sending the tweets is always trying to make parts of it in bold. 一切正常,除了发送推文的人总是试图用粗体制作部分内容。 And it looks like this
<b>Bla</b>
. 它看起来像
<b>Bla</b>
。 It looks like this on his twitter site and also on my page. 它在Twitter网站上和我的页面上看起来都是这样的。
I dont know what he does wrong and I dont care, I am just wondering if I could transform those in actual bold at my site by adding another few lines to the function above? 我不知道他做错了什么,我也不在乎,我只是想知道我是否可以通过在上面的函数中添加另外几行来在我的网站上实际变换那些?
Check the source, there's a good chance that it i actually <
and >
instead of <
and >
. 检查来源,很有可能它实际上
<
和>
而不是<
和>
。 so do a regex that looks for <b>
那么寻找
<b>
的正则表达式也是如此
note the 'g' flag that tells the replacement to apply to all of the matches. 注意'g'标志告诉替换应用于所有匹配。
function replaceURLWithHTMLLinks(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text
.replace(exp,"<a href='$1' target='_blank'>$1</a>")
.replace(new RegExp('<b>','g'),'<b>')
.replace(new RegExp('</b>','g'),'</b>');
}
This is just a guess, but is the Twitter plug-in returning the HTML escaped - 这只是一个猜测,但是Twitter插件返回HTML转义 -
<b>
if it is you could replace the escaped content - 如果它是你可以替换转义的内容 -
replace(new RegExp('<b>','g'),'<b>').replace(RegExp('</b>','g'),'</b>')
the html characters have been encoded html字符已编码
try this 尝试这个
http://www.prodevtips.com/2008/10/21/jquery-plugin-html-decode-and-encode/ http://www.prodevtips.com/2008/10/21/jquery-plugin-html-decode-and-encode/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.