2
There is a similar question, but the result is comparatively specific..手把助手用包含匹配URL的HTML字符串替换字符串中的URL?
我有段线串看起来像这样(从文本区域保存):
"Here are some links\n\nhttp://www.example.com is one of them\n\nand http://duckduckgo.com is another"
我会如何替换每个URL,http://www.example.com
和http://duckduckgo.com
,具有:
<a href="http://www.example.com" target="_blank">www.example.com</a>
and
<a href="http://duckduckgo.com" target="_blank">duckduckgo.com</a>
这样所有的网址都会显示为链接,其文本排除了http:// ..
"Here are some links\n\n<a href="http://www.example.com" target="_blank">www.example.com</a> is one of them\n\nand <a href="http://duckduckgo.com" target="_blank">duckduckgo.com</a> is another"
要呈现此:
这里有一些链接
和duckduckgo.com之一是另一个
从车把帮手..
Handlebars.registerHelper('linkingplaintext', function(plaintext) {
// some code to replace the URLs with their equivalent links
return new Handlebars.SafeString(linkedplainText);
});
感谢您的强烈的示例..已更新的问题与一个更可变的字符串,可能会发生,其中可能包括文本之前给定的链接 – Stacks 2015-02-09 03:11:01
真正辉煌 – Stacks 2015-02-09 06:13:22